Alexis

Hide Settings Tab in Page edition

Recommended Posts

Alexis    3

Hi everyone,

When i edit a page in the admin (logged as an editor), i would like to hide the "Settings" tab or at leat the part "Who can access this page?".

Is there a simple way to do that?

Thanks.

Share this post


Link to post
Share on other sites
Soma    6,128

You can't do this just out of the box but with a autoload module you could easily accomplish this. Also there's useful needed features in there for an editor.

At least the "Who can access this page"?

Why is this a problem? It may not necessary in most cases...

In PW, almost all of these things can be changed modified using hooks on what builds them in the admin.

So if you really want to do it, the best way would be through a module like the /site/modules/HelloWorld.module

It shows some example of hooks and is worth a look and have a play anyway.

This following module hides the InputfieldWrapper "Who can access this page"? in the settings tab for user having a role "editor". 

<?php

class AdminHelperHooks extends WireData implements Module {

    public static function getModuleInfo() {
        return array(
            'title' => 'My Admin Helper Hooks',
            'version' => 1,
            'singular' => true,
            'autoload' => true
            );
    }

    public function init() {
        // add hook to the page edit module and the method that creates the wanted fieldset
        $this->addHookAfter('ProcessPageEdit::buildFormRoles', $this, "removeSettings");
    }

    function removeSettings(HookEvent $event){
        // check what role the user has, if not has editor role do nothing
        if(!wire("user")->hasRole("editor")) return;
        
        // $event->return being the inputfield wrapper
        $wrapper = $event->return; 
        
        // set the inputfield wrapper to hidden
        $wrapper->collapsed = Inputfield::collapsedHidden;

        // we're done
    }
}

Create a new file AdminHelperHooks.module with this code in a new folder /site/modules/AdminHelperHooks/

Install and test with editor user.

  • Like 11

Share this post


Link to post
Share on other sites
Alexis    3

Thanks a lot Soma.

Your code works perfectly.

At least the "Who can access this page"?
Why is this a problem? It may not necessary in most cases...

The problem is just i don't want to give the editor (=my client) too much information.

I'm building a tipical website with a few levels of options. All options are buit in the aplication and are activated according to the level the client want.

This means I have specific fields permissions and roles for each level, which appears all in "who can access this page?", but doesn't match the client choice.

Share this post


Link to post
Share on other sites
mrkhan    10

Hello Soma,

i am using version 2.5 of PW and trying to hide settings tab on user role webmaster (which is my defied role)

i have use bellow code

<?php

class AdminHelperHooks extends WireData implements Module {

    public static function getModuleInfo() {
        return array(
            'title' => 'My Admin Helper Hooks',
            'version' => 1,
            'singular' => true,
            'autoload' => true
            );
    }

    public function init() {
        // add hook to the page edit module and the method that creates the wanted fieldset
        $this->addHookAfter('ProcessPageEdit::buildFormRoles', $this, "removeSettings");
    }

    function removeSettings(HookEvent $event){
        // check what role the user has, if not has editor role do nothing
        if(!wire("user")->hasRole("webmaster")) return;
        
        // $event->return being the inputfield wrapper
        $wrapper = $event->return; 
        
        // set the inputfield wrapper to hidden
        $wrapper->collapsed = Inputfield::collapsedHidden;

        // we're done
    }
}

in site/modules/AdminHelperHooks/AdminHelperHooks.module

also i install the module but when i login as user using webmaster  group i can see settings tab. how i hide page setting tab for this type of user ?

Thanks

Share this post


Link to post
Share on other sites
Martijn Geerts    3,178

@mrkhan: There have been changes in ProcessPageEdit recently. The tabs need to be deleted manually. The code below works in 2.5.25 (dev).

(don't know if thats the case for 2.5 and if so could you report this back)

function removeSettings(HookEvent $event){
	// check what role the user has, if not has editor role do nothing
	if(!wire("user")->hasRole("webmaster")) return;

	// $event->return being the inputfield wrapper
	$wrapper = $event->return; 

	// set the inputfield wrapper to hidden
	$wrapper->collapsed = Inputfield::collapsedHidden;

	// Get the active Object (ProcessPageEdit)
	$process = $event->object;

        // Remove the Settings tab with the ID
	$process->removeTab('ProcessPageEditSettings');

	// we're done
}
  • Like 3

Share this post


Link to post
Share on other sites
formulate    34

@mrkhan: There have been changes in ProcessPageEdit recently. The tabs need to be deleted manually. The code below works in 2.5.25 (dev).

(don't know if thats the case for 2.5 and if so could you report this back)

function removeSettings(HookEvent $event){
	// check what role the user has, if not has editor role do nothing
	if(!wire("user")->hasRole("webmaster")) return;

	// $event->return being the inputfield wrapper
	$wrapper = $event->return; 

	// set the inputfield wrapper to hidden
	$wrapper->collapsed = Inputfield::collapsedHidden;

	// Get the active Object (ProcessPageEdit)
	$process = $event->object;

        // Remove the Settings tab with the ID
	$process->removeTab('ProcessPageEditSettings');

	// we're done
}

Hi Martijn,

I wasn't able to get this to work with dev 2.5.22. All it does is swap the places of the delete and settings tabs. Any advice?

Thanks,

K.

Share this post


Link to post
Share on other sites
adrian    7,667

Not sure why this hasn't been mentioned, so I am wondering if I am missing something relevant, but why not use the $template->noSettings option?

Do you need to hide on a page basis, rather than per template?

Anyway, if it suits your needs, turn on advanced mode in your config.php file and then you will have a Disable Settings Tab? option on the Template's System Tab.

Hope that might help.

  • Like 4

Share this post


Link to post
Share on other sites
Martijn Geerts    3,178

There must be recent changes I guess, but this one works:
 
oops this one is for delete tab

<?php

class AdminHelperHooks extends WireData implements Module {

    public static function getModuleInfo() {
        return array(
            'title' => 'My Admin Helper Hooks',
            'version' => 1,
            'singular' => true,
            'autoload' => true
            );
    }

    public function init() {
        // add hook to the page edit module and the method that creates the wanted fieldset
        $this->addHookAfter('ProcessPageEdit::buildFormDelete', $this, "removeDelete");
    }

    function removeDelete(HookEvent $event){
        // $event->return being the inputfield wrapper
        $wrapper = $event->return;
        // set the inputfield wrapper to hidden
        $wrapper->collapsed = Inputfield::collapsedHidden;
        // Get the active Object (ProcessPageEdit)
        $process = $event->object;
        // Remove the Settings tab with the ID
        $process->removeTab('ProcessPageEditDelete');
        // we're done
    }
}

For settings tab

<?php

class AdminHelperHooks extends WireData implements Module {

    public static function getModuleInfo() {
        return array(
            'title' => 'My Admin Helper Hooks',
            'version' => 1,
            'singular' => true,
            'autoload' => true
            );
    }

    public function init() {
        // add hook to the page edit module and the method that creates the wanted fieldset
        $this->addHookAfter('ProcessPageEdit::buildFormSettings', $this, "removeSettings");
    }

    function removeSettings(HookEvent $event){
        // $event->return being the inputfield wrapper
        $wrapper = $event->return;
        // set the inputfield wrapper to hidden
        $wrapper->collapsed = Inputfield::collapsedHidden;
        // Get the active Object (ProcessPageEdit)
        $process = $event->object;
        // Remove the Settings tab with the ID
        $process->removeTab('ProcessPageEditSettings');
        // we're done
    }
} 
  • Like 2

Share this post


Link to post
Share on other sites
bmacnaughton    30
On 3/14/2015 at 2:15 PM, adrian said:

Anyway, if it suits your needs, turn on advanced mode in your config.php file and then you will have a Disable Settings Tab? option on the Template's System Tab.

Woohoo! Thanks.

$config->advanced = true; does the trick!

Share this post


Link to post
Share on other sites
bmacnaughton    30
On 3/14/2015 at 2:21 PM, Martijn Geerts said:

There must be recent changes I guess, but this one works:

I'm working in version 3 and can't remove the settings tab using your example. Maybe something new has changed?

But $config->advanced = true; works perfectly and is a better solution as it's already per-template.

Share this post


Link to post
Share on other sites
adrian    7,667
4 hours ago, bmacnaughton said:

I'm working in version 3 and can't remove the settings tab using your example. Maybe something new has changed?

But $config->advanced = true; works perfectly and is a better solution as it's already per-template.

My module (https://processwire.com/talk/topic/9496-restrict-tab-view/) mentioned above still works fine in PW 3 if that's helpful for you.

  • Like 2

Share this post


Link to post
Share on other sites
bmacnaughton    30
4 hours ago, adrian said:

My module (https://processwire.com/talk/topic/9496-restrict-tab-view/) mentioned above still works fine in PW 3 if that's helpful for you.

Thank you. I really appreciate the link and the code being on github. I learn a lot by reading code and yours is very helpful. I've solved the problem for one template but your solution is more general so when the inevitable additional template comes along, I'll most likely move to your module.

Thanks for putting it together and pointing me at it.

  • Like 1

Share this post


Link to post
Share on other sites

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.