mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
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:
parent
ea6a60533a
commit
555ee1549b
@ -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
|
||||
*/
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user