From 9b7542b9f1beb96f16123beebdd13728783f6dcd Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 21 Feb 2010 17:14:19 -0800 Subject: Add Menu::add_before() --- modules/gallery/libraries/Menu.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'modules/gallery/libraries/Menu.php') diff --git a/modules/gallery/libraries/Menu.php b/modules/gallery/libraries/Menu.php index 7c76ab04..fef07916 100644 --- a/modules/gallery/libraries/Menu.php +++ b/modules/gallery/libraries/Menu.php @@ -184,7 +184,7 @@ class Menu_Core extends Menu_Element { } /** - * Add a new element to this menu + * Add a new element to this menu, after the specific element */ public function add_after($target_id, $new_menu_element) { $copy = array(); @@ -198,6 +198,21 @@ class Menu_Core extends Menu_Element { return $this; } + /** + * Add a new element to this menu, before the specific element + */ + public function add_before($target_id, $new_menu_element) { + $copy = array(); + foreach ($this->elements as $id => $menu_element) { + if ($id == $target_id) { + $copy[$new_menu_element->id] = $new_menu_element; + } + $copy[$id] = $menu_element; + } + $this->elements = $copy; + return $this; + } + /** * Remove an element from the menu */ -- cgit v1.2.3