$item = new ElggMenuItem('thewire', elgg_echo('thewire'), 'thewire/all');\r
elgg_register_menu_item('site', $item);\r
\r
- // remove entity menu items edit and access because they don't apply here.\r
- elgg_register_plugin_hook_handler('prepare', 'menu:entity', 'thewire_remove_entity_menu_items');\r
+ // remove edit and access and add thread, reply, view previous\r
+ elgg_register_plugin_hook_handler('register', 'menu:entity', 'thewire_setup_entity_menu_items');\r
\r
// Extend system CSS with our own styles, which are defined in the thewire/css view\r
elgg_extend_view('css', 'thewire/css');\r
return null;\r
}\r
\r
+/**\r
+ * Sets up the entity menu for thewire\r
+ *\r
+ * Adds reply, thread, and view previous links. Removes edit and access.\r
+ *\r
+ * @param string $hook\r
+ * @param string $type\r
+ * @param array $value\r
+ * @param array $params\r
+ * @return array\r
+ */\r
+function thewire_setup_entity_menu_items($hook, $type, $value, $params) {\r
+ $handler = elgg_extract('handler', $params, false);\r
+ if ($handler != 'thewire') {\r
+ return $value;\r
+ }\r
+\r
+ foreach ($value as $index => $item) {\r
+ $name = $item->getName();\r
+ if ($name == 'access' || $name == 'edit') {\r
+ unset($value[$index]);\r
+ }\r
+ }\r
+\r
+ $entity = $params['entity'];\r
+\r
+ if (elgg_is_logged_in()) {\r
+ $options = array(\r
+ 'name' => 'reply',\r
+ 'text' => elgg_echo('thewire:reply'),\r
+ 'href' => "thewire/reply/$entity->guid",\r
+ 'priority' => 150,\r
+ );\r
+ $value[] = ElggMenuItem::factory($options);\r
+ }\r
+\r
+ if ($entity->reply) {\r
+ $options = array(\r
+ 'name' => 'previous',\r
+ 'text' => elgg_echo('thewire:previous'),\r
+ 'href' => "thewire/previous/$entity->guid",\r
+ 'priority' => 160,\r
+ );\r
+ $value[] = ElggMenuItem::factory($options);\r
+ }\r
+\r
+ $options = array(\r
+ 'name' => 'thread',\r
+ 'text' => elgg_echo('thewire:thread'),\r
+ 'href' => "thewire/thread/$entity->wire_thread",\r
+ 'priority' => 170,\r
+ );\r
+ $value[] = ElggMenuItem::factory($options);\r
+\r
+ return $value;\r
+}\r
+\r
/**\r
* Runs unit tests for the wire\r
*/\r
$value[] = $CONFIG->pluginspath . 'thewire/tests/regex.php';\r
return $value;\r
}\r
-\r
-/**\r
- * Removes the access and edit items from the entity menu\r
- *\r
- * @param type $hook\r
- * @param type $type\r
- * @param type $value\r
- * @param type $params\r
- * @return array\r
- */\r
-function thewire_remove_entity_menu_items($hook, $type, $value, $params) {\r
- if (elgg_in_context('thewire')) {\r
- $menu = elgg_extract('default', $value, array());\r
- foreach ($menu as $i => $entry) {\r
- $name = $entry->getName();\r
- if ($name == 'access' || $name == 'edit') {\r
- unset($value['default'][$i]);\r
- }\r
- }\r
- return $value;\r
- }\r
-}
\ No newline at end of file