Jump to content

Triggers

From NusaATK

You can use the following triggers on a node:

  • preAdd
  • postAdd
  • preUpdate
  • postUpdate
  • preDelete
  • postDelete

to perform various tasks after or before an action has been executed.

FULL List added June 2017

  • preAddToEditArray(&$record, $mode) [class.atknode.inc at line 2100, column 5
  • preAddToViewArray(&$record, $mode) [class.atknode.inc at line 2115, column 5
  • preAdd(&$record) [class.atknode.inc at line 4174, column 5
  • preUpdate(&$record) [class.atknode.inc at line 4213, column 5
  • preDelete($record) [class.atknode.inc at line 4231, column 5
  • preCopy(&$record) [class.atknode.inc at line 4282, column 5
  • preNotify($action, &$record) [class.atknode.inc at line 5069, column 5
  • preFilter() [class.atkfrontcontroller.inc at line 546, column 15
  • preActionPerformed($action, &$record) [class.atkactionlistener.inc at line 133, column 5
  • postInit() [class.atkattribute.inc at line 2027, column 5
  • postAdd($record, $mode = "add") [class.atknode.inc at line 4158, column 5
  • postUpdate($record) [class.atknode.inc at line 4196, column 5
  • postDel($record) [class.atknode.inc at line 4243, column 5
  • postDelete($record) [class.atknode.inc at line 4260, column 5
  • postFilter() [class.atkfrontcontroller.inc at line 561, column 15


These triggers take only 1 argument, which is an array with the record.

Pre triggers

If the trigger is a pre- trigger, you can make the argument to be a pointer and you can adjust the record before it is added/updated/deleted.

Pre-trigger returning false does not necessarily halt the action being performed (because of backwards compatability). To actually halt the action, use the triggerError-function. Doing so will add an entry in the record called 'atkerror'. Upon detecting this, the action will halt. And the message in the atkerror entry will be displayed as an error. For more information on the triggerError function, please see the API documentation on the function. eg

if ($width > 400 || $height > 400) {
        triggerError($record, "picture", "You can upload only pictures smaller than 400 pixels in height and width");
    }

an example for having the preAdd and preUpdate triggers run the same code:

  function preAdd(&$record) 
  {
    $this->makeNames($record);
    return true;
  } 

  function preUpdate(&$record) 
  {
    $this->makeNames($record);
    return true;
  } 

  function makeNames(&$record)  
  {
    $record["full_name"] = $record["names_slot_1"] . $record["names_slot_2"];
  }

Listeners

Note that triggers are superseded by Listeners, a more flexible concept as Listeners can be applied at runtime.