diff options
author | cash <cash.costello@gmail.com> | 2011-11-12 14:28:52 -0500 |
---|---|---|
committer | cash <cash.costello@gmail.com> | 2011-11-16 19:53:04 -0500 |
commit | 11aacb4f048e659d1b86a6ba229438444a186142 (patch) | |
tree | d35da1535860f8883e5c92d3571fa2090890d85a /documentation/examples/events | |
parent | 08a2fc293a9ecb92caa778d32689b595bee1d68d (diff) | |
download | elgg-11aacb4f048e659d1b86a6ba229438444a186142.tar.gz elgg-11aacb4f048e659d1b86a6ba229438444a186142.tar.bz2 |
added better plugin skeleton and added documentation to some of the examples
Diffstat (limited to 'documentation/examples/events')
-rw-r--r-- | documentation/examples/events/advanced.php | 7 | ||||
-rw-r--r-- | documentation/examples/events/all.php | 16 | ||||
-rw-r--r-- | documentation/examples/events/basic.php | 14 | ||||
-rw-r--r-- | documentation/examples/events/emit.php | 7 | ||||
-rw-r--r-- | documentation/examples/events/trigger.php | 11 |
5 files changed, 36 insertions, 19 deletions
diff --git a/documentation/examples/events/advanced.php b/documentation/examples/events/advanced.php index 22a407579..73edea9da 100644 --- a/documentation/examples/events/advanced.php +++ b/documentation/examples/events/advanced.php @@ -1,10 +1,13 @@ <?php +/** + * This snippets demonstrates how returning false changes the normal operation + * of Elgg. + */ elgg_register_event_handler('create', 'object', 'example_event_handler'); -function example_event_handler($event, $type, $params) { +function example_event_handler($event, $type, $object) { // Don't allow any non-admin users to create objects // Returning false from this function will halt the creation of the object. return elgg_is_admin_logged_in(); } - diff --git a/documentation/examples/events/all.php b/documentation/examples/events/all.php index 238178312..0ad02c1d4 100644 --- a/documentation/examples/events/all.php +++ b/documentation/examples/events/all.php @@ -1,17 +1,24 @@ <?php +/** + * If you register an 'all' string for the event name, the handler function will + * be called for all events with that name, regardless of event type. The same + * can be done for the event type argument. Registering 'all' for both + * argyuments results in a handler being called for every event. + */ elgg_register_event_handler('all', 'object', 'example_event_handler'); // This function will be called for any event of type 'object' -function example_event_handler($event, $type, $params) { +function example_event_handler($event, $type, $object) { // check what sort of object is passed - if ($params instanceof ElggObject) { - $subtype = $params->getSubtype(); + if ($object instanceof ElggObject) { + $subtype = $object->getSubtype(); - switch($subtype) { + switch ($subtype) { case 'blog': case 'thewire': case 'pages': + // prevent these object subtypes from being saved or changed return false; default: return true; @@ -21,4 +28,3 @@ function example_event_handler($event, $type, $params) { return true; } - diff --git a/documentation/examples/events/basic.php b/documentation/examples/events/basic.php index 91704e60b..ca2762344 100644 --- a/documentation/examples/events/basic.php +++ b/documentation/examples/events/basic.php @@ -1,13 +1,17 @@ <?php +/** + * This snippet demonstrates how to register for an event. It dumps the + * parameters that the handler receives to the screen. The third argument + * of the handler function is an object that is related to the event. For + * the 'init', 'system' eveny, it is null. + */ elgg_register_event_handler('init', 'system', 'example_event_handler'); -function example_event_handler($event, $type, $params) { +function example_event_handler($event, $type, $object) { var_dump($event); - var_dump($object_type); - var_dump($params); + var_dump($type); + var_dump($object); return true; } - - diff --git a/documentation/examples/events/emit.php b/documentation/examples/events/emit.php deleted file mode 100644 index b917c6dc0..000000000 --- a/documentation/examples/events/emit.php +++ /dev/null @@ -1,7 +0,0 @@ -<?php - -$params = new ElggObject(); -elgg_trigger_event('test', 'example', $params); - -// handlers would be registered by saying -elgg_register_event_handler('test', 'example', 'example_event_handler'); diff --git a/documentation/examples/events/trigger.php b/documentation/examples/events/trigger.php new file mode 100644 index 000000000..6ce3a76f0 --- /dev/null +++ b/documentation/examples/events/trigger.php @@ -0,0 +1,11 @@ +<?php +/** + * These two snippets demonstrates triggering an event and how to register for + * that event. + */ + +$object = new ElggObject(); +elgg_trigger_event('test', 'example', $object); + +// elsewhere a handler could be registered by saying +elgg_register_event_handler('test', 'example', 'example_event_handler'); |