From b134c8c70cc310e8170da44d1e2291f507cb31ff Mon Sep 17 00:00:00 2001 From: Matt Beckett Date: Sun, 15 Jul 2012 01:40:02 -0600 Subject: persist 'selected' state of site menu --- engine/lib/navigation.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'engine') diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php index 4ff009bfb..8845d5164 100644 --- a/engine/lib/navigation.php +++ b/engine/lib/navigation.php @@ -308,6 +308,41 @@ function elgg_site_menu_setup($hook, $type, $return, $params) { $return['more'] = array_splice($return['default'], $max_display_items); } } + + // check if we have anything selected + $selected = false; + foreach ($return as $section_name => $section) { + foreach ($section as $key => $item) { + if ($item->getSelected()) { + $selected = true; + break 2; + } + } + } + + if (!$selected) { + // nothing selected, match by handler + $handler = get_input('handler'); + + foreach ($return as $section_name => $section) { + foreach ($section as $key => $item) { + // determine the 'handler' of this url, if there is one + if (strpos($item->getHref(), elgg_get_site_url()) === 0) { + // this is an internal link, so it has a page handler + $path = array(str_replace(elgg_get_site_url(), '', $item->getHref())); + $separators = array('/', '?', '#'); + foreach ($separators as $separator) { + $path = explode($separator, $path[0]); + } + + if ($path[0] == $handler) { + $return[$section_name][$key]->setSelected(true); + break 2; + } + } + } + } + } return $return; } -- cgit v1.2.3 From b336f1065259b28113be1bca11dabe3ac167bd1a Mon Sep 17 00:00:00 2001 From: Matt Beckett Date: Tue, 17 Jul 2012 22:39:49 -0600 Subject: switched to matching by link name - same results, simpler code --- engine/lib/navigation.php | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'engine') diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php index 8845d5164..a9d28e22e 100644 --- a/engine/lib/navigation.php +++ b/engine/lib/navigation.php @@ -321,21 +321,12 @@ function elgg_site_menu_setup($hook, $type, $return, $params) { } if (!$selected) { - // nothing selected, match by handler - $handler = get_input('handler'); - + // nothing selected, match name to context foreach ($return as $section_name => $section) { foreach ($section as $key => $item) { - // determine the 'handler' of this url, if there is one + // only highlight internal links if (strpos($item->getHref(), elgg_get_site_url()) === 0) { - // this is an internal link, so it has a page handler - $path = array(str_replace(elgg_get_site_url(), '', $item->getHref())); - $separators = array('/', '?', '#'); - foreach ($separators as $separator) { - $path = explode($separator, $path[0]); - } - - if ($path[0] == $handler) { + if ($item->getName() == elgg_get_context()) { $return[$section_name][$key]->setSelected(true); break 2; } -- cgit v1.2.3