This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hello, I would need to add specific permissions to hide/show "meta" and "settings" tabs when editing a static page (using the cool plugin of Rainlab).
I know I should do via custom plugin into register() function and listening on Event (for example I succesfully added a new tab) but I would need more info to catch tabs with permission please. Thank you!
read this for permissions:
https://octobercms.com/docs/backend/users#features
And use the backend.form.extendFields
event with removeField()
method to remove the field if user doesn't have permission to use it.
You could also use filterFields method as shown here:
https://octobercms.com/docs/backend/forms#filter-form-fields
ok thank you, I was trying something similar, but how can I target correctly the entire tab?
for example, something like this doesn't work:
\Event::listen('backend.form.extendFields', function ($widget) {
$widget->removeField("settings");
$widget->removeField("meta");
}
In CMS or Static Page when I open a page to edit, there are still both the tabs...
Last updated
I found a solution... it seems that after removing all the fields into a tab, event the tab itself will be hidden...
So for example to remove the tab "Settings" and "Meta" in the CMS section:
{
$widget->removeField('settings[description]');
$widget->removeField('settings[layout]');
$widget->removeField('settings[is_hidden]');
$widget->removeField('settings[meta_title]');
$widget->removeField('settings[meta_description]');
}
or for example to remove from the Static Pages menu related to some permission:
if (\BackendAuth::check()) {
$backend_user = \BackendAuth::getUser();
if (!$backend_user->hasAccess('xxx.yyy.some_editor_permissions') ) {
$widget->removeField('viewBag[description]');
$widget->removeField('viewBag[layout]');
$widget->removeField('viewBag[is_hidden]');
$widget->removeField('viewBag[navigation_hidden]');
$widget->removeField('viewBag[meta_title]');
$widget->removeField('viewBag[meta_description]');
}
}
Last updated
1-4 of 4