Jump to content

Recommended Posts

Posted

Hi Guys

I have a question about the Add Page Shortcut Functionality. In General you can set the family settings on template so that you have to choose a new Parent when adding a new page of the defined template with the shortcut menu. In my case I can add new "Newsletter" Pages but I have to choose under which Parent it should be added. But as a "Clinic" - User I can only add the Newsletter Pages under the Parent Page which belongs to this User (was made with a Hook inside Page::addable / Page:editable).  Because of that I only see one Parent Item in the Dropdown Shortcut Menu which is correct.

post-3125-0-71095100-1463643462_thumb.pn

Can this Selection be skipped when the shortcut menu only has one Parent to choose (Also in ProLister "Add New")?

Posted

Do I have to make a hook inside ProcessPageAdd::___executeTemplate or something like that? 

Posted

This worked for me:

I'm doing a "addHookBefore" inside the ProcessPageAdd::executeTemplate Method.

public function init() {

     if(!$this->user->isSuperuser() && $this->user->hasRole("XXXXXXXX")) $this->addHookBefore('ProcessPageAdd::executeTemplate', $this, 'redirectParent');

}

Inside the redirectParent Hook Method

public function redirectParent(HookEvent $event){

     //Get ID from URL
     $templateID = (int) $this->input->get->template_id;

     //Check if it's a Newsletter
     if($templateID == 66){
          
          //Get the Parent Page specified by the choose_sender_2016 Pagefield in the user & newsletter Template
	  $parent = $this->pages->get("template=newsletter-clinic, choose_sender_2016={$this->user->choose_sender_2016}");
	  
          //Check if a Parent was found
          if($parent->id){
                
                //Skip the Parent Selection with a redirect
		$url = "./?parent_id=" . $parent->id; 
	        if($this->wire('input')->get('modal')) $url .= "&modal=1";
	        $this->wire('session')->redirect($url);
	  }
     }

}
  • Like 3

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
×
×
  • Create New...