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
This commit is contained in:
Sam Minnee 2008-11-17 21:45:01 +00:00
parent ea6a60533a
commit 555ee1549b
3 changed files with 27 additions and 6 deletions

View File

@ -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
*/

View File

@ -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) {
$menuItems = self::$menu_items;
// 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);

View File

@ -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;
}