]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
cleaned up the plugin hooks documentation
authorcash <cash.costello@gmail.com>
Sat, 12 Nov 2011 19:49:36 +0000 (14:49 -0500)
committercash <cash.costello@gmail.com>
Thu, 17 Nov 2011 00:53:04 +0000 (19:53 -0500)
documentation/examples/hooks/advanced.php [new file with mode: 0644]
documentation/examples/hooks/all.php [moved from documentation/examples/hooks/register/all.php with 71% similarity]
documentation/examples/hooks/basic.php
documentation/examples/hooks/register/advanced.php [deleted file]
documentation/examples/hooks/register/basic.php [deleted file]
documentation/examples/hooks/register/emit.php [deleted file]
documentation/examples/hooks/trigger.php [new file with mode: 0644]
documentation/examples/hooks/trigger/advanced.php [deleted file]
documentation/examples/hooks/trigger/basic.php [deleted file]

diff --git a/documentation/examples/hooks/advanced.php b/documentation/examples/hooks/advanced.php
new file mode 100644 (file)
index 0000000..ca036c4
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+/**
+ * This snippet demonstrates how to change the value of a hook. The content
+ * passed into the hook is 'This is some Sample Content.'. After the two hook
+ * handlers are done, the new content is 'This is some $@mple Content.'.
+ */
+
+// the output:page hook is triggered by elgg_view_page().
+elgg_register_plugin_hook_handler('output', 'page', 'example_plugin_hook_handler', 600);
+elgg_register_plugin_hook_handler('output', 'page', 'example_plugin_hook_handler_2', 601);
+
+function example_plugin_hook_handler($hook, $type, $value, $params) {
+       // change a to @
+       $value = str_replace('a', '@', $value);
+
+       return $value;
+}
+
+function example_plugin_hook_handler_2($hook, $type, $value, $params) {
+       // change S to $
+       $value = str_replace('S', '$', $value);
+
+       return $value;
+}
+
+$content = 'This is some Sample Content.';
+
+echo elgg_view_page('Title', $content);
similarity index 71%
rename from documentation/examples/hooks/register/all.php
rename to documentation/examples/hooks/all.php
index 0ff19bc86d24d17675d9a847768db36809591a3b..76b562335cfc80f8c5484d2505ffd508c70d8261 100644 (file)
@@ -1,4 +1,8 @@
 <?php
+/**
+ * This snippet demonstrates how to register for multiple hooks with the same
+ * type.
+ */
 
 elgg_register_plugin_hook_handler('all', 'system', 'example_plugin_hook_handler');
 
index 71076ee96b586ece678c124b567d27c19f6db0b4..734d9e884829e0e8b7d2b35d55e95058a5587fd0 100644 (file)
@@ -1,34 +1,17 @@
 <?php
+/**
+ * The handler for a plugin hook receives information about the hook (name and
+ * type), the current value for the hook, and parameters related to the hook.
+ */
 
-elgg_register_plugin_hook_handler('get_items', 'example', 'example_plugin_hook');
-elgg_register_plugin_hook_handler('get_items', 'example', 'example_plugin_hook_2');
+elgg_register_plugin_hook_handler('forward', '404', 'example_plugin_hook_handler');
 
-$params = array('username' => 'Joe');
-$items = elgg_trigger_plugin_hook('get_items', 'example', $params, $default);
+function example_plugin_hook_handler($hook, $type, $value, $params) {
+       var_dump($hook);
+       var_dump($type);
+       var_dump($value);
+       var_dump($params);
 
-var_dump($items);
-
-function example_plugin_hook($hook, $type, $value, $params) {
-       if (is_array($value)) {
-               $value[] = "Hook Value 1";
-               $value[] = "Hook Value 2";
-       }
-
-       return $value;
-}
-
-function example_plugin_hook_2($hook, $type, $value, $params) {
-       $username = isset($params['username']) ? $params['username'] : NULL;
-       if (is_array($value)) {
-               switch($username) {
-                       case 'Joe':
-                               $value[] = "Joe's item";
-                               break;
-                       case 'John':
-                               $value[] = "Joe's item";
-                               break;
-               }
-       }
-
-       return $value;
+       // we are not changing $value so return null
+       return null;
 }
diff --git a/documentation/examples/hooks/register/advanced.php b/documentation/examples/hooks/register/advanced.php
deleted file mode 100644 (file)
index e3951c1..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-<?php
-
-// the output:page hook is triggered by elgg_view_page().
-elgg_register_plugin_hook_handler('output', 'page', 'example_plugin_hook_handler', 600);
-elgg_register_plugin_hook_handler('output', 'page', 'example_plugin_hook_handler_2', 601);
-
-function example_plugin_hook_handler($event, $type, $value, $params) {
-       // change A to @
-       $value = str_replace('A', '@', $value);
-
-       return $value;
-}
-
-function example_plugin_hook_handler_2($event, $type, $value, $params) {
-       // change S to $
-       $value = str_replace('S', '$', $value);
-
-       return $value;
-}
-
-$content = 'This is some Sample Content.';
-
-echo elgg_view_page('Title', $content);
\ No newline at end of file
diff --git a/documentation/examples/hooks/register/basic.php b/documentation/examples/hooks/register/basic.php
deleted file mode 100644 (file)
index 20493e2..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-
-elgg_register_plugin_hook_handler('forward', 'system', 'example_plugin_hook_handler');
-
-function example_plugin_hook_handler($event, $type, $value, $params) {
-       var_dump($event);
-       var_dump($type);
-       var_dump($value);
-       var_dump($params);
-       
-       return true;
-}
-
-
diff --git a/documentation/examples/hooks/register/emit.php b/documentation/examples/hooks/register/emit.php
deleted file mode 100644 (file)
index 8382d72..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<?php
-
-// @todo this is an event, not a hook
-elgg_register_event_handler('test', 'example', 'example_init_system_callback');
-
-$params = new ElggObject();
-elgg_trigger_event('test', 'example', $params);
diff --git a/documentation/examples/hooks/trigger.php b/documentation/examples/hooks/trigger.php
new file mode 100644 (file)
index 0000000..4216fd6
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+/**
+ * The current value for the hook is passed into the trigger function. Handlers
+ * can change this value. In this snippet, we check if the value of true was
+ * changed by the handler functions.
+ */
+
+$result = elgg_trigger_plugin_hook('get_status', 'example', null, true);
+
+if ($result) {
+       var_dump('Plugin hook says ok!');
+} else {
+       var_dump('Plugin hook says no.');
+}
diff --git a/documentation/examples/hooks/trigger/advanced.php b/documentation/examples/hooks/trigger/advanced.php
deleted file mode 100644 (file)
index 5901a06..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<?php
-
-$default = array('Entry 1', 'Entry 2', 'Entry 3');
-
-$menu = elgg_trigger_plugin_hook('get_menu_items', 'menu', null, $default);
-
-foreach ($menu as $item) {
-       var_dump($item);
-}
diff --git a/documentation/examples/hooks/trigger/basic.php b/documentation/examples/hooks/trigger/basic.php
deleted file mode 100644 (file)
index ea27a8a..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<?php
-
-$result = elgg_trigger_plugin_hook('get_status', 'example', null, true);
-
-if ($result) {
-       var_dump('Plugin hook says ok!');
-} else {
-       var_dump('Plugin hook says no.');
-}