API:invokeEvent

From MODx Wiki
Jump to: navigation, search
 API Function Definition: 
invokeEvent
Versions 
> 0.6.0
Return Values
Success: Values of each plugin
Fail: bool false
Data Type 
array
Object Hierarchy 
DocumentParser
array invokeEvent(string $evtName[, array $extParams]);


Executes plugins based on $evtName. See System Events for a list of defined events for $evtName.

Examples

This is not an API Function and requires extensive knowledge of the MODx core in order to be used correctly. Use of this function in areas other than the core code is discouraged and the team may provide little or no help on the use of this function.

Related Functions

Function Source

File: manager/includes/document.parser.class.inc.php
Line: 2244
  1. function invokeEvent($evtName, $extParams= array ()) {
  2. if (!$evtName)
  3. return false;
  4. if (!isset ($this->pluginEvent[$evtName]))
  5. return false;
  6. $el= $this->pluginEvent[$evtName];
  7. $results= array ();
  8. $numEvents= count($el);
  9. if ($numEvents > 0)
  10. for ($i= 0; $i < $numEvents; $i++) { // start for loop
  11. $pluginName= $el[$i];
  12. // reset event object
  13. $e= & $this->Event;
  14. $e->_resetEventObject();
  15. $e->name= $evtName;
  16. $e->activePlugin= $pluginName;
  17.  
  18. // get plugin code
  19. if (isset ($this->pluginCache[$pluginName])) {
  20. $pluginCode= $this->pluginCache[$pluginName];
  21. $pluginProperties= $this->pluginCache[$pluginName . "Props"];
  22. } else {
  23. $sql= "SELECT * FROM " . $this->getFullTableName("site_plugins") . " WHERE name='" . $pluginName . "' AND disabled=0;";
  24. $result= $this->dbQuery($sql);
  25. if ($this->recordCount($result) == 1) {
  26. $row= $this->fetchRow($result);
  27. $pluginCode= $this->pluginCache[$row['name']]= $row['plugincode'];
  28. $pluginProperties= $this->pluginCache[$row['name'] . "Props"]= $row['properties'];
  29. } else {
  30. $pluginCode= $this->pluginCache[$pluginName]= "return false;";
  31. $pluginProperties= '';
  32. }
  33. }
  34.  
  35. // load default params/properties
  36. $parameter= $this->parseProperties($pluginProperties);
  37. if (!empty ($extParams))
  38. $parameter= array_merge($parameter, $extParams);
  39.  
  40. // eval plugin
  41. $this->evalPlugin($pluginCode, $parameter);
  42. if ($e->_output != "")
  43. $results[]= $e->_output;
  44. if ($e->_propagate != true)
  45. break;
  46. }
  47. $e->activePlugin= "";
  48. return $results;

Notes

Personal tools