aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/navigation.php64
-rw-r--r--engine/lib/views.php37
2 files changed, 101 insertions, 0 deletions
diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php
index 75c5958f4..7b8c32f02 100644
--- a/engine/lib/navigation.php
+++ b/engine/lib/navigation.php
@@ -8,6 +8,70 @@
*/
/**
+ * Register an item for an Elgg menu
+ *
+ * @param string $menu_name The name of the menu: site, page, userhover,
+ * userprofile, groupprofile, or any custom menu
+ * @param mixed $menu_item A ElggMenuItem object or an array of options in format:
+ * name => STR Menu item identifier (required)
+ * title => STR Menu item title (required)
+ * url => STR Menu item URL (required)
+ * contexts => ARR Page context strings
+ * section => STR Menu section identifier
+ * tooltip => STR Menu item tooltip
+ * selected => BOOL Is this menu item currently selected
+ * parent_name => STR Identifier of the parent menu item
+ *
+ * Custom options can be added as key value pairs.
+ *
+ * @return bool
+ * @since 1.8.0
+ */
+function elgg_register_menu_item($menu_name, $menu_item) {
+ global $CONFIG;
+
+ if (!isset($CONFIG->menus[$menu_name])) {
+ $CONFIG->menus[$menu_name] = array();
+ }
+
+ if (is_array($menu_item)) {
+ $menu_item = ElggMenuItem::factory($menu_item);
+ if (!$menu_item) {
+ return false;
+ }
+ }
+
+ $CONFIG->menus[$menu_name][] = $menu_item;
+ return true;
+}
+
+/**
+ * Remove an item from a menu
+ *
+ * @param string $menu_name The name of the menu
+ * @param string $item_name The unique identifier for this menu item
+ *
+ * @return bool
+ * @since 1.8.0
+ */
+function elgg_unregister_menu_item($menu_name, $item_name) {
+ global $CONFIG;
+
+ if (!isset($CONFIG->menus[$menu_name])) {
+ return false;
+ }
+
+ foreach ($CONFIG->menus[$menu_name] as $index => $menu_object) {
+ if ($menu_object->name == $item_name) {
+ unset($CONFIG->menus[$menu_name][$index]);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/**
* Deprecated by elgg_add_submenu_item()
*
* @see elgg_add_submenu_item()
diff --git a/engine/lib/views.php b/engine/lib/views.php
index ade5ff678..71922cb6c 100644
--- a/engine/lib/views.php
+++ b/engine/lib/views.php
@@ -644,6 +644,43 @@ function elgg_view_layout($layout_name, $vars = array()) {
}
/**
+ * Render a menu
+ *
+ * @param string $menu_name The name of the menu
+ * @param array $vars An associative array of display options for the menu.
+ * Options include:
+ * sort_by => string or php callback
+ * string options: 'name', 'title' (default), 'order' (registration order)
+ * php callback: a compare function for usort
+ *
+ * @return string
+ * @since 1.8.0
+ */
+function elgg_view_menu($menu_name, array $vars = array()) {
+
+ $vars['name'] = $menu_name;
+
+ $sort_by = elgg_get_array_value('sort_by', $vars, 'title');
+
+ // Give plugins a chance to add menu items just before creation.
+ // This supports context sensitive menus (ex. user hover).
+ elgg_trigger_plugin_hook('register', "menu:$menu_name", $vars, NULL);
+
+ $builder = new ElggMenuBuilder($menu_name);
+ $vars['menu'] = $builder->getMenu($sort_by);
+ $vars['selected_item'] = $builder->getSelected();
+
+ // Let plugins modify the menu
+ $vars['menu'] = elgg_trigger_plugin_hook('prepare', "menu:$menu_name", $vars, $vars['menu']);
+
+ if (elgg_view_exists("navigation/menu/$menu_name")) {
+ return elgg_view("navigation/menu/$menu_name", $vars);
+ } else {
+ return elgg_view("navigation/menu/default", $vars);
+ }
+}
+
+/**
* Returns a string of a rendered entity.
*
* Entity views are either determined by setting the view property on the entity