Skip to content

Commit

Permalink
Fix settings
Browse files Browse the repository at this point in the history
  • Loading branch information
sangnguyenplus committed Jun 13, 2024
1 parent 6c68ea4 commit 7a8bd4b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 59 deletions.
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
10 changes: 5 additions & 5 deletions src/Facades/Honeypot.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
101 changes: 48 additions & 53 deletions src/Forms/Settings/HoneypotSettingForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
}
}

0 comments on commit 7a8bd4b

Please sign in to comment.