From 7a8bd4b003e2ee1d6aaba4190d6e7d3ef43afe1c Mon Sep 17 00:00:00 2001 From: Sang Nguyen Date: Thu, 13 Jun 2024 15:16:57 +0700 Subject: [PATCH] Fix settings --- plugin.json | 2 +- src/Facades/Honeypot.php | 10 +- src/Forms/Settings/HoneypotSettingForm.php | 101 ++++++++++----------- 3 files changed, 54 insertions(+), 59 deletions(-) diff --git a/plugin.json b/plugin.json index 3f1228c..941996f 100644 --- a/plugin.json +++ b/plugin.json @@ -5,7 +5,7 @@ "provider": "FriendsOfBotble\\Honeypot\\Providers\\HoneypotServiceProvider", "author": "Friends of Botble", "url": "https://friendsofbotble.com", - "version": "1.0.2", + "version": "1.0.3", "description": "Preventing spam submitted through forms", "minimum_core_version": "7.2.6" } diff --git a/src/Facades/Honeypot.php b/src/Facades/Honeypot.php index 93b8c4b..4375c19 100644 --- a/src/Facades/Honeypot.php +++ b/src/Facades/Honeypot.php @@ -12,15 +12,15 @@ * @method static string validFromFieldName() * @method static \Carbon\CarbonInterface validFrom() * @method static string encryptedValidFrom() - * @method static \FriendsOfBotble\Honeypot\Honeypot registerForm(string $form, string $request, string $title) + * @method static static registerForm(string $form, string $request, string $title) * @method static array getForms() * @method static bool enabledForForm(string $form) * @method static string getFormByRequest(string $request) - * @method string string getFormSettingKey(string $form) - * @method string string getSettingKey(string $key) - * @method string mixed getSetting(string $key, mixed $default = null) + * @method static string getFormSettingKey(string $form) + * @method static string getSettingKey(string $key) + * @method static mixed|null getSetting(string $key, mixed|null $default = null) * @method static string render() - * @method static void validate(string $value) + * @method static void validate(string|null $value) * * @see \FriendsOfBotble\Honeypot\Honeypot */ diff --git a/src/Forms/Settings/HoneypotSettingForm.php b/src/Forms/Settings/HoneypotSettingForm.php index 9fa4625..0a9e3a8 100644 --- a/src/Forms/Settings/HoneypotSettingForm.php +++ b/src/Forms/Settings/HoneypotSettingForm.php @@ -10,7 +10,6 @@ use Botble\Base\Forms\Fields\NumberField; use Botble\Base\Forms\Fields\OnOffCheckboxField; use Botble\Base\Forms\Fields\OnOffField; -use Botble\Base\Forms\FormCollapse; use Botble\Setting\Forms\SettingForm; use FriendsOfBotble\Honeypot\Facades\Honeypot; use FriendsOfBotble\Honeypot\Http\Requests\Settings\HoneypotSettingRequest; @@ -25,60 +24,56 @@ public function setup(): void ->setSectionTitle(trans('plugins/fob-honeypot::honeypot.settings.title')) ->setSectionDescription(trans('plugins/fob-honeypot::honeypot.settings.description')) ->setValidatorClass(HoneypotSettingRequest::class) - ->addCollapsible( - FormCollapse::make('settings') - ->targetField( - Honeypot::getSettingKey('enabled'), - OnOffField::class, - OnOffFieldOption::make() - ->label(trans('plugins/fob-honeypot::honeypot.settings.enable')) - ->value(Honeypot::enabled()) - ->toArray(), + ->add( + Honeypot::getSettingKey('enabled'), + OnOffField::class, + OnOffFieldOption::make() + ->label(trans('plugins/fob-honeypot::honeypot.settings.enable')) + ->value(Honeypot::enabled()) + ->toArray(), + ) + ->addOpenCollapsible(Honeypot::getSettingKey('enabled'), '1', Honeypot::enabled()) + ->add( + Honeypot::getSettingKey('amount_of_seconds'), + NumberField::class, + NumberFieldOption::make() + ->label(trans('plugins/fob-honeypot::honeypot.settings.amount_of_seconds')) + ->value(Honeypot::getSetting('amount_of_seconds', 3)) + ->helperText(trans('plugins/fob-honeypot::honeypot.settings.amount_of_seconds_helper')) + ->toArray() + ) + ->add( + Honeypot::getSettingKey('show_disclaimer'), + OnOffCheckboxField::class, + CheckboxFieldOption::make() + ->label(trans('plugins/fob-honeypot::honeypot.settings.show_disclaimer')) + ->value(Honeypot::getSetting('show_disclaimer')) + ->helperText( + trans('plugins/fob-honeypot::honeypot.settings.show_disclaimer_helper', [ + 'default' => 'This site is protected by Honeypot.', + ]) ) - ->isOpened(Honeypot::enabled()) - ->fieldset(function (HoneypotSettingForm $form) { - $form - ->add( - Honeypot::getSettingKey('amount_of_seconds'), - NumberField::class, - NumberFieldOption::make() - ->label(trans('plugins/fob-honeypot::honeypot.settings.amount_of_seconds')) - ->value(Honeypot::getSetting('amount_of_seconds', 3)) - ->helperText(trans('plugins/fob-honeypot::honeypot.settings.amount_of_seconds_helper')) - ->toArray() - ) - ->add( - Honeypot::getSettingKey('show_disclaimer'), - OnOffCheckboxField::class, - CheckboxFieldOption::make() - ->label(trans('plugins/fob-honeypot::honeypot.settings.show_disclaimer')) - ->value(Honeypot::getSetting('show_disclaimer')) - ->helperText( - trans('plugins/fob-honeypot::honeypot.settings.show_disclaimer_helper', [ - 'default' => 'This site is protected by Honeypot.', - ]) - ) - ->toArray() - ) - ->add( - Honeypot::getSettingKey('enable_form_label'), - LabelField::class, - LabelFieldOption::make() - ->label(trans('plugins/fob-honeypot::honeypot.settings.enable_form')) - ->toArray() - ); + ->toArray() + ) + ->add( + Honeypot::getSettingKey('enable_form_label'), + LabelField::class, + LabelFieldOption::make() + ->label(trans('plugins/fob-honeypot::honeypot.settings.enable_form')) + ->toArray() + ); - foreach (Honeypot::getForms() as $form => $title) { - $this->add( - Honeypot::getFormSettingKey($form), - OnOffField::class, - OnOffFieldOption::make() - ->label($title) - ->value(Honeypot::enabledForForm($form)) - ->toArray() - ); - } - }) + foreach (Honeypot::getForms() as $form => $title) { + $this->add( + Honeypot::getFormSettingKey($form), + OnOffField::class, + OnOffFieldOption::make() + ->label($title) + ->value(Honeypot::enabledForForm($form)) + ->toArray() ); + } + + $this->addCloseCollapsible(Honeypot::getSettingKey('enabled'), '1'); } }