Jump to content

Hide Settings Tab in Page edition


Alexis
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 months later...
  • 1 year later...
  • 4 months later...

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

Link to comment
Share on other sites

  • 4 weeks later...

@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
Link to comment
Share on other sites

  • 1 month later...

@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.

Link to comment
Share on other sites

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
  • Thanks 2
Link to comment
Share on other sites

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 3
Link to comment
Share on other sites

  • 2 weeks later...
  • 2 years later...
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!

  • Like 1
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 2 years later...
42 minutes ago, buster808 said:

Hi, does the settings page not have its own template somewhere.

I would like to keep Name but hide everything else on the settings tab in page.

It sounds like you may be confusing pages and tabs: the settings tab (included on each page) doesn't have a template of its own. None of the tabs do -- only pages have (or, more specifically, use) templates.

This thread has ideas on how to hide the settings tab with code, and if you enable the advanced mode via site/config.php, you should find settings for hiding the tab and moving name to the Content tab. More details here: 

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

53 minutes ago, teppo said:

It sounds like you may be confusing pages and tabs: the settings tab (included on each page) doesn't have a template of its own. None of the tabs do -- only pages have (or, more specifically, use) templates.

This thread has ideas on how to hide the settings tab with code, and if you enable the advanced mode via site/config.php, you should find settings for hiding the tab and moving name to the Content tab. More details here: 

Excellent thanks Teppo didn't know about the advanced mode.

Link to comment
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
 Share

  • Recently Browsing   0 members

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