From 555ee1549b657e188f5654c11a2f1b2886c1abee Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Mon, 17 Nov 2008 21:45:01 +0000 Subject: [PATCH] BUGFIX #3063: Allow old-school method of adding menu items to LeftAndMiain: git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.3@66062 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/CMSMain.php | 14 ++++++++++++++ code/CMSMenu.php | 4 +++- code/LeftAndMain.php | 15 ++++++++++----- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/code/CMSMain.php b/code/CMSMain.php index ed497994..12a869e0 100644 --- a/code/CMSMain.php +++ b/code/CMSMain.php @@ -128,6 +128,20 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr //------------------------------------------------------------------------------------------// // Main UI components + /** + * Override {@link LeftAndMain} Link to allow blank URL segment for CMSMain. + * + * @return string + */ + public function Link($action = null) { + return Controller::join_links( + $this->stat('url_base', true), + $this->stat('url_segment', true), // in case we want to change the segment + '/', // trailing slash needed if $action is null! + "$action" + ); + } + /** * Return the entire site tree as a nested set of ULs */ diff --git a/code/CMSMenu.php b/code/CMSMenu.php index 0184d8fd..60c00419 100644 --- a/code/CMSMenu.php +++ b/code/CMSMenu.php @@ -82,8 +82,10 @@ class CMSMenu extends Object implements Iterator * @return boolean Success */ public static function add_menu_item($code, $menuTitle, $url, $controllerClass = null, $priority = -1) { + // If a class is defined, then force the use of that as a code. This helps prevent menu item duplication + if($controllerClass) $code = $controllerClass; + $menuItems = self::$menu_items; - if(isset($menuItems[$code])) return false; return self::replace_menu_item($code, $menuTitle, $url, $controllerClass, $priority); diff --git a/code/LeftAndMain.php b/code/LeftAndMain.php index 2555b6bf..2273d23d 100644 --- a/code/LeftAndMain.php +++ b/code/LeftAndMain.php @@ -200,6 +200,9 @@ class LeftAndMain extends Controller { * @return string */ public function Link($action = null) { + // Handle missing url_segments + if(!$this->stat('url_segment', true)) + self::$url_segment = $this->class; return Controller::join_links( $this->stat('url_base', true), $this->stat('url_segment', true), @@ -287,11 +290,14 @@ class LeftAndMain extends Controller { $linkingmode = ""; - if(!(strpos($this->Link(), $menuItem->url) === false)) { + if(strpos($this->Link(), $menuItem->url) !== false) { + if($this->Link() == $menuItem->url) { + $linkingmode = "current"; + // default menu is the one with a blank {@link url_segment} - if(singleton($menuItem->controller)->stat('url_segment') == '') { - if($this->Link() == $this->stat('url_base').'/') - $linkingmode = "current"; + } else if(singleton($menuItem->controller)->stat('url_segment') == '') { + if($this->Link() == $this->stat('url_base').'/') $linkingmode = "current"; + } else { $linkingmode = "current"; } @@ -317,7 +323,6 @@ class LeftAndMain extends Controller { // if no current item is found, assume that first item is shown //if(!isset($foundCurrent)) - return $menu; }