This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

ivan_g
ivan_g

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!

mjauvin
mjauvin

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

ivan_g
ivan_g

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

ivan_g
ivan_g

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

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.