Jump to content
kreativmonkey

How to use $page->isNew()

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?

Share this post


Link to post
Share on other sites

isNew() will only be true, if a page was never saved to the db, which in terms of backend creation of pages is only till after the page add screen, where you put in the title/name of a page.

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...