Jump to content

How to use $page->isNew()


kreativmonkey
 Share

Recommended Posts

I'm working on a notification Module that hooks into Page::saveReady . Then i will check if a page is New, Changed or Deleted to notify with different text and filter the right template.

I'm working on a notification Module that hooks into Page::saveReady . Then i will check if a page is New, Changed or Deleted to notify with different text and filter the right template.

public function hookPageSave(HookEvent $event){
  $page = $event->arguments[0];
  $template = $page->template;
  $templates = $this->notificationChange;

  // if page have no id => return
  if(!$page->id || !$page->title) return;


  // Check if page is Deleted
  if($page->isTrash()){
    if(!in_array($template->name, $this->notificationDelete)) return;

    $this->log->save('debug', "Page is Deleted: $page->title");
    //$this->hookPageDelete($event);
    return;
  }

  if($page->isNew()){
    if(!in_array($template->name, $this->notificationPublish)) return;

    $this->log->save('debug', "New Page: $page->title");
    return;
  }

  // Check if page is Changed
  if($page->isChanged() && !$page->isNew()){
    if(!in_array($template->name, $this->notificationChange)) return;

    $this->log->save('debug', "Page Changed: $page->title");
    //$this->hookPageChange($event);
    return;
  }

i create a new post and if i publish this post i've got false on the $page->isNew() call. I worked around a little bit but i don't know how i can find out if a page is new ore just changed.

For trigger changes i must change the hook to Page::saveReady (from Page::saved) but what do i need to trigger if the page is new?

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