Extending Backend Settings to add fields (such as maintenance mode, Customize-backend page)
If you want to extend a Settings of another plugin or backend section to add fields i.e. the ones that don't have an exclusive controller but rather are just a settings page, you need to extend the form widget associated with it. Now at first if you look at System\Controllers\Settings, the class responsible for rendering settings it may feel like a good idea to extend that and called extendFormFields from your Plugin boot but it wouldn't work since the Settings controller is a special controller that doesn't implement form behavior but directly loads a formwidget internally. So to extend it, you have to hook into it's Form's extension methods.
As an example, let us extend the Maintainence Mode page from another plugin. In the Plugin.php boot method, include:
Event::listen('backend.form.extendFields', function ($widget) {
if (!$widget->getController() instanceof \System\Controllers\Settings) {
return;
}
// Only for the MaintenanceSetting model
if (!$widget->model instanceof \Cms\Models\MaintenanceSetting) {
return;
}
$widget->addFields([
'disable_feature' => [
'label' => 'Disable Feature?',
'type' => 'switch'
]
]);
});
There are no comments yet
Be the first one to comment