Spica Posted February 25, 2015 Posted February 25, 2015 I want to prevent the settings tab for specific roles. Is it a good way to do that in an admin template with a hook to ProcessPageEdit and set the $useSettings = false; Do I better use a before or after hook and how best to write it?
Fokke Posted February 25, 2015 Posted February 25, 2015 Hi Spica! Create a new permission called "page-edit-show-settings-tab" and adjust the roles to fit your needs. In /site/templates/admin.php add the following before the line: require($config->paths->adminTemplates . 'controller.php'); function hideSettingsTab(HookEvent $event) { // Get the page being edited $page = $event->object->getPage(); if (!wire('user')->hasPermission('page-edit-show-settings-tab', $page)) { $page->template->set('noSettings', 1); } } $wire->addHookBefore('ProcessPageEdit::buildForm', null, 'hideSettingsTab'); After a quick test, this seems to work fine on my setup. 12
Spica Posted February 25, 2015 Author Posted February 25, 2015 Nice solution. Ended up with this as a autoload module <?php class Helloworld extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Hello World', 'version' => 1, 'singular' => true, 'autoload' => true, 'summary' => 'Anpassungen', 'icon' => 'smile-o', ); } public function init() { $this->addHookBefore('ProcessPageEdit::buildForm', $this, 'hideSettingsTab'); } function hideSettingsTab(HookEvent $event) { if($this->user->hasRole("presenter")) { $page = $event->object->getPage(); $page->template->set('noSettings', 1); } } } 7
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now