Jump to content

Hide Settings Tab in Page edition


mrkhan
 Share

Recommended Posts

Hello,

 

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

@mrkhan
 
As you found out, that only removes part of the settings page. Sorry to say that there is no simple way to do this yet on a per-role basis.  There is a way you can do it for a template regardless of role but it needs a little code.
 
To Remove The Tab Regardless Of Role...
 
To remove the whole tab you need to set the 'noSettings' property on the template used by those pages. If you already have a template file set up for that template then paste this in, edit as needed, and view any page that uses the template...

$temp = $page->template;
$temp->set('noSettings', 1);
$temp->save();

When you next edit any pages using that template in the admin interface, you'll find that the settings tab has gone. To get it back change the 1 to a 0 and re-view the page in the front-end and the tab will be back in the admin interface.
 
If you don't have a template file attached to the template just create one and add it to the template, view a page, and remove the template file afterwards.

Edited to add: Actually, there might be a hook that can be used for this. I'll see what I can find later if no-one else gets to it first.

Here's a working idea - totally untested and probably not working...

<?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()
    {
        $this->addHookBefore('ProcessPageEdit::buildForm', $this, "removeSettings");
    }


    function removeSettings(HookEvent $event)
    {
        if(wire('user')->hasRole('webmaster')) {
            wire('page')->template->set('noSettings', 1);
        }
    }
}
Edited by netcarver
  • Like 3
Link to comment
Share on other sites

Hello @netcarver

thanks for reply but none of your solution is working. as my website is using templetes with head.inc in top, i have added

$temp = $page->template;
$temp->set('noSettings', 1);
$temp->save();

also your second solution is not working too.

in head.inc of site template, but in admin when i goto to edit any page, i can still see the settings tab.

on this link https://processwire.com/talk/topic/4680-block-access-to-settings-delete-and-view-tabs-for-page/#entry83981

provided by @LostKobrakai

i got this code

// in a autoload module like HelloWorld.module

public function init(){
    $this->addHookAfter("ProcessPageEdit::buildForm", $this, "buildFormHook");    
}

public function buildFormHook(HookEvent $event){
    
    // get page edited by ProcessPageEdit

    $page = $event->object->getPage();
    
    // conditions

    if(wire("user")->hasRole("superuser")) return;
    
    if($page->id == 1039) {
        
        // the form InputfieldWrapper returned by ProcessPageEdit::buildForm()
        $form = $event->return;
        
        // find the desired InputfieldWrapper's and remove them from the form

        $fieldset = $form->find("id=ProcessPageEditSettings")->first();
        $form->remove($fieldset);
        
        $fieldset = $form->find("id=ProcessPageEditDelete")->first();
        $form->remove($fieldset);
        
    }

} 

and when i create new controller and install that controller, it shows settings tab but when i click nothing happen, settings tab is gone but still i can see settings tab button, how can i also hide that button?

Thanks

Link to comment
Share on other sites

  • 1 year later...

Check this link: https://processwire.com/talk/topic/4680-block-access-to-settings-delete-and-view-tabs-for-page/#entry118215

and when i create new controller and install that controller, it shows settings tab but when i click nothing happen, settings tab is gone but still i can see settings tab button, how can i also hide that button?

Thanks

print the variables $tabs to get the correct id, or hide all tabs if you prefer by returning empty array.

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

×
×
  • Create New...