Jump to content

block access to "Settings", "Delete" and "View" tabs for page


Joe
 Share

Recommended Posts

Hi everyone!

Is it possible to eliminate access for a non-superuser to the "Settings", "Delete" and "View" tabs on a specific page?

It is a site-settings page without a template file and it really doesn´t make any sense and is confusing to the users if they can rename it etc.

Thanks

Link to comment
Share on other sites

;) Answering my own question:

So I´ve succeeded, though it was kind of tedious and I consider it a hack only:

In \site\templates-admin\default.php:

  1. detect the page´s headline
    $trigger = strip_tags($this->fuel->processHeadline ? $this->fuel->processHeadline : $page->get("title|name"));
     
    
  2. If the headline is my site-settings page´s, set the relevant list items style to "display: none;":
    if( $trigger == "Site Settings"):
    $content = str_replace("<li class='Inputfield InputfieldWrapper Inputfield_ ui-widget' id='ProcessPageEditSettings' title='Settings'>", "<li style = \"display: none;\">", $content);
    $content = str_replace("<li class='Inputfield InputfieldWrapper Inputfield_ ui-widget' id='ProcessPageEditDelete' title='Delete'>", "<li style = \"display: none;\">", $content);
    $content = str_replace("<li class='Inputfield InputfieldMarkup Inputfield_ ui-widget InputfieldWrapper' id='ProcessPageEditView' title='View'>", "<li style = \"display: none;\">", $content);            
    endif;
    
    That does it. But like I said, I think it´s just a hack. So I will not set the topic to "solved", maybe there is a better way to do it.
Link to comment
Share on other sites

Hi Joe. A simple search via google (processwire.com hide settings tab) found my thread a while ago:

http://processwire.com/talk/topic/3159-hide-settings-tab-in-page-edition/

Here's another example doing it differently:

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

} 

This works fine in PW.

  • Like 4
Link to comment
Share on other sites

  • 1 year later...
  • 1 year later...

A search to hide "delete" tab brought me here. Thanks soma for the code.

Just want to leave a note for others: This doesn't work currently. The form still gets changed, but the tabs will stay, as Ryan changed the tab generation part.

In order to hide the tab(s), you have to add another hook to edit form:

 $this->addHook('ProcessPageEdit::getTabs', $this, 'hookEditFormTabs');
public function hookEditFormTabs($event) {        
// logic check
//        if ($this->user->isSuperuser()) return;
//        if ($this->page->id != 29) return;
        $tabs = $event->return;
        unset($tabs['ProcessPageEditDelete']);
        $event->return = $tabs;
    }
  • Like 2
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...