Events hook

Permalink
I have an existing system that was built for me. I have a problem in that an event hook fires off when ever an entry is added or edited in the custom object. What I really want is for the event to fire off only when a new entry is added, so not when an existing one is edited. The controller code is below. Any help appreciated.

<?php 
defined('C5_EXECUTE') or die(_("Access Denied."));
class DashboardChurchesAddChurchController extends Controller {
   public function on_start() {
      $this->error = Loader::helper('validation/error');
      Loader::model('attribute/categories/churches', 'churches');
   }
   public function view(){
      $html = Loader::helper('html');
      $form = Loader::helper('form');
      $this->set('form', $form);
   }
   private function saveData($Church) {
      Loader::model('attribute/categories/churches', 'churches');
      $attribs = ChurchesAttributeKey::getList();

 
hutman replied on at Permalink Reply
hutman
I believe if you just move

Events::fire('NEW_CHURCH_ADDED',$Church);

below
$this->saveData($Church);

in the add function that should fix your issue.
justynpride replied on at Permalink Reply
Perfect. Thanks so much.

This website stores cookies on your computer. These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media. To find out more about the cookies we use, see our Privacy Policy.