Jump to content

hook into new page creation


Neeks
 Share

Recommended Posts

Looking to hook into creating a new page after the new page has a $page->id. 

Any one know what the correct hook might be?

public function init(){
     $this->pages->addHookAfter('????', $this, 'myHookFunction');
}

Once I have the correct hook does any one know I can access the $newPage->id ?

public function myHookFunction(HookEvent $event){
      $newPage = $event->arguments[0];  //would this be correct?
      $this->error('it worked here is the id of your new page:'.$newPage->id);
}

I might be able to jerry-rig it, if there is no hook, by hooking to save function, and comparing creation date with current date or something less elegant....I'm open to better and maybe less creative ways of solving this problem ;-)

Link to comment
Share on other sites

This is what you are looking for:

$this->pages->addHookAfter('added', $this, 'hookAdded');

public function hookAdded(HookEvent $event){
   $newPage = $event->arguments[0];
   $this->message('it worked here is the id of your new page:'.$newPage->id); // Yes, this will work 
}

  • Like 4
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...