aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcash <cash.costello@gmail.com>2011-11-12 14:49:36 -0500
committercash <cash.costello@gmail.com>2011-11-16 19:53:04 -0500
commit0ec65a0130347b3b846628e9e59a1f1cbf0f0e06 (patch)
treea2a3a3fb11b6c1ca318d923e1cc949a2b10dd76b
parent11aacb4f048e659d1b86a6ba229438444a186142 (diff)
downloadelgg-0ec65a0130347b3b846628e9e59a1f1cbf0f0e06.tar.gz
elgg-0ec65a0130347b3b846628e9e59a1f1cbf0f0e06.tar.bz2
cleaned up the plugin hooks documentation
-rw-r--r--documentation/examples/hooks/advanced.php28
-rw-r--r--documentation/examples/hooks/all.php (renamed from documentation/examples/hooks/register/all.php)4
-rw-r--r--documentation/examples/hooks/basic.php41
-rw-r--r--documentation/examples/hooks/register/advanced.php23
-rw-r--r--documentation/examples/hooks/register/basic.php14
-rw-r--r--documentation/examples/hooks/register/emit.php7
-rw-r--r--documentation/examples/hooks/trigger.php14
-rw-r--r--documentation/examples/hooks/trigger/advanced.php9
-rw-r--r--documentation/examples/hooks/trigger/basic.php9
9 files changed, 58 insertions, 91 deletions
diff --git a/documentation/examples/hooks/advanced.php b/documentation/examples/hooks/advanced.php
new file mode 100644
index 000000000..ca036c46a
--- /dev/null
+++ b/documentation/examples/hooks/advanced.php
@@ -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);
diff --git a/documentation/examples/hooks/register/all.php b/documentation/examples/hooks/all.php
index 0ff19bc86..76b562335 100644
--- a/documentation/examples/hooks/register/all.php
+++ b/documentation/examples/hooks/all.php
@@ -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');
diff --git a/documentation/examples/hooks/basic.php b/documentation/examples/hooks/basic.php
index 71076ee96..734d9e884 100644
--- a/documentation/examples/hooks/basic.php
+++ b/documentation/examples/hooks/basic.php
@@ -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
index e3951c19c..000000000
--- a/documentation/examples/hooks/register/advanced.php
+++ /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
index 20493e200..000000000
--- a/documentation/examples/hooks/register/basic.php
+++ /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
index 8382d72ca..000000000
--- a/documentation/examples/hooks/register/emit.php
+++ /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
index 000000000..4216fd6c0
--- /dev/null
+++ b/documentation/examples/hooks/trigger.php
@@ -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
index 5901a06e0..000000000
--- a/documentation/examples/hooks/trigger/advanced.php
+++ /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
index ea27a8a98..000000000
--- a/documentation/examples/hooks/trigger/basic.php
+++ /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.');
-}