diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-09-15 15:40:51 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-09-15 15:40:51 +0000 |
commit | ea4403c9240c3778cddc90d48d0a59c4d47dd2d8 (patch) | |
tree | d62822795c186d7de87f3f5e337283d8007dae2a /documentation/examples/events | |
parent | 4d008fefd2882a51309b5c6a7c3c7775fb34270d (diff) | |
download | elgg-ea4403c9240c3778cddc90d48d0a59c4d47dd2d8.tar.gz elgg-ea4403c9240c3778cddc90d48d0a59c4d47dd2d8.tar.bz2 |
Adding documentation and examples.
git-svn-id: http://code.elgg.org/elgg/trunk@6933 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'documentation/examples/events')
-rw-r--r-- | documentation/examples/events/advanced.php | 10 | ||||
-rw-r--r-- | documentation/examples/events/all.php | 24 | ||||
-rw-r--r-- | documentation/examples/events/basic.php | 13 | ||||
-rw-r--r-- | documentation/examples/events/basic.php.out | 0 | ||||
-rw-r--r-- | documentation/examples/events/emit.php | 7 |
5 files changed, 54 insertions, 0 deletions
diff --git a/documentation/examples/events/advanced.php b/documentation/examples/events/advanced.php new file mode 100644 index 000000000..c6fc2d0fb --- /dev/null +++ b/documentation/examples/events/advanced.php @@ -0,0 +1,10 @@ +<?php + +register_elgg_event_handler('create', 'object', 'example_event_handler'); + +function example_event_handler($event, $type, $params) { + // Don't allow any non-admin users to create objects + // Returning false from this function will halt the creation of the object. + return isadminloggedin(); +} + diff --git a/documentation/examples/events/all.php b/documentation/examples/events/all.php new file mode 100644 index 000000000..63959a9d2 --- /dev/null +++ b/documentation/examples/events/all.php @@ -0,0 +1,24 @@ +<?php + +register_elgg_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) { + // check what sort of object is passed + if ($params instanceof ElggObject) { + $subtype = $params->getSubtype(); + + switch($subtype) { + case 'blog': + case 'thewire': + case 'pages': + return false; + default: + return true; + } + + } + + return true; +} + diff --git a/documentation/examples/events/basic.php b/documentation/examples/events/basic.php new file mode 100644 index 000000000..b274137b8 --- /dev/null +++ b/documentation/examples/events/basic.php @@ -0,0 +1,13 @@ +<?php + +register_elgg_event_handler('init', 'system', 'example_event_handler'); + +function example_event_handler($event, $type, $params) { + var_dump($event); + var_dump($object_type); + var_dump($params); + + return true; +} + + diff --git a/documentation/examples/events/basic.php.out b/documentation/examples/events/basic.php.out new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/documentation/examples/events/basic.php.out diff --git a/documentation/examples/events/emit.php b/documentation/examples/events/emit.php new file mode 100644 index 000000000..f4cd1b127 --- /dev/null +++ b/documentation/examples/events/emit.php @@ -0,0 +1,7 @@ +<?php + +$params = new ElggObject(); +trigger_elgg_event('test', 'example', $params); + +// handlers would be registered by saying +register_elgg_event_handler('test', 'example', 'example_event_handler'); |