Jump to content

Recommended Posts

Posted

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?

Posted

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. 

  • Like 12
Posted

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);
		}
	}

}
  • Like 7

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...