mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
ENHANCEMENT Section icons in CMS (#7269)
This commit is contained in:
parent
0d1e4cece5
commit
4029f96728
@ -437,75 +437,87 @@ class LeftAndMain extends Controller implements PermissionProvider {
|
|||||||
* Returns the main menu of the CMS. This is also used by init()
|
* Returns the main menu of the CMS. This is also used by init()
|
||||||
* to work out which sections the user has access to.
|
* to work out which sections the user has access to.
|
||||||
*
|
*
|
||||||
|
* @param Boolean
|
||||||
* @return SS_List
|
* @return SS_List
|
||||||
*/
|
*/
|
||||||
public function MainMenu() {
|
public function MainMenu($cached = true) {
|
||||||
// Don't accidentally return a menu if you're not logged in - it's used to determine access.
|
if(!isset($this->_cache_MainMenu) || !$cached) {
|
||||||
if(!Member::currentUser()) return new ArrayList();
|
// Don't accidentally return a menu if you're not logged in - it's used to determine access.
|
||||||
|
if(!Member::currentUser()) return new ArrayList();
|
||||||
|
|
||||||
// Encode into DO set
|
// Encode into DO set
|
||||||
$menu = new ArrayList();
|
$menu = new ArrayList();
|
||||||
$menuItems = CMSMenu::get_viewable_menu_items();
|
$menuItems = CMSMenu::get_viewable_menu_items();
|
||||||
if($menuItems) {
|
if($menuItems) {
|
||||||
foreach($menuItems as $code => $menuItem) {
|
foreach($menuItems as $code => $menuItem) {
|
||||||
// alternate permission checks (in addition to LeftAndMain->canView())
|
// alternate permission checks (in addition to LeftAndMain->canView())
|
||||||
if(
|
if(
|
||||||
isset($menuItem->controller)
|
isset($menuItem->controller)
|
||||||
&& $this->hasMethod('alternateMenuDisplayCheck')
|
&& $this->hasMethod('alternateMenuDisplayCheck')
|
||||||
&& !$this->alternateMenuDisplayCheck($menuItem->controller)
|
&& !$this->alternateMenuDisplayCheck($menuItem->controller)
|
||||||
) {
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$linkingmode = "link";
|
$linkingmode = "link";
|
||||||
|
|
||||||
if($menuItem->controller && get_class($this) == $menuItem->controller) {
|
if($menuItem->controller && get_class($this) == $menuItem->controller) {
|
||||||
$linkingmode = "current";
|
|
||||||
} else if(strpos($this->Link(), $menuItem->url) !== false) {
|
|
||||||
if($this->Link() == $menuItem->url) {
|
|
||||||
$linkingmode = "current";
|
$linkingmode = "current";
|
||||||
|
} else if(strpos($this->Link(), $menuItem->url) !== false) {
|
||||||
// default menu is the one with a blank {@link url_segment}
|
if($this->Link() == $menuItem->url) {
|
||||||
} else if(singleton($menuItem->controller)->stat('url_segment') == '') {
|
$linkingmode = "current";
|
||||||
if($this->Link() == $this->stat('url_base').'/') {
|
|
||||||
|
// default menu is the one with a blank {@link url_segment}
|
||||||
|
} else if(singleton($menuItem->controller)->stat('url_segment') == '') {
|
||||||
|
if($this->Link() == $this->stat('url_base').'/') {
|
||||||
|
$linkingmode = "current";
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
$linkingmode = "current";
|
$linkingmode = "current";
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
$linkingmode = "current";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// already set in CMSMenu::populate_menu(), but from a static pre-controller
|
||||||
|
// context, so doesn't respect the current user locale in _t() calls - as a workaround,
|
||||||
|
// we simply call LeftAndMain::menu_title_for_class() again
|
||||||
|
// if we're dealing with a controller
|
||||||
|
if($menuItem->controller) {
|
||||||
|
$defaultTitle = LeftAndMain::menu_title_for_class($menuItem->controller);
|
||||||
|
$title = _t("{$menuItem->controller}.MENUTITLE", $defaultTitle);
|
||||||
|
} else {
|
||||||
|
$title = $menuItem->title;
|
||||||
|
}
|
||||||
|
|
||||||
|
$menu->push(new ArrayData(array(
|
||||||
|
"MenuItem" => $menuItem,
|
||||||
|
"Title" => Convert::raw2xml($title),
|
||||||
|
"Code" => DBField::create_field('Text', $code),
|
||||||
|
"Link" => $menuItem->url,
|
||||||
|
"LinkingMode" => $linkingmode
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// already set in CMSMenu::populate_menu(), but from a static pre-controller
|
|
||||||
// context, so doesn't respect the current user locale in _t() calls - as a workaround,
|
|
||||||
// we simply call LeftAndMain::menu_title_for_class() again
|
|
||||||
// if we're dealing with a controller
|
|
||||||
if($menuItem->controller) {
|
|
||||||
$defaultTitle = LeftAndMain::menu_title_for_class($menuItem->controller);
|
|
||||||
$title = _t("{$menuItem->controller}.MENUTITLE", $defaultTitle);
|
|
||||||
} else {
|
|
||||||
$title = $menuItem->title;
|
|
||||||
}
|
|
||||||
|
|
||||||
$menu->push(new ArrayData(array(
|
|
||||||
"MenuItem" => $menuItem,
|
|
||||||
"Title" => Convert::raw2xml($title),
|
|
||||||
"Code" => DBField::create_field('Text', $code),
|
|
||||||
"Link" => $menuItem->url,
|
|
||||||
"LinkingMode" => $linkingmode
|
|
||||||
)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->_cache_MainMenu = $menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if no current item is found, assume that first item is shown
|
return $this->_cache_MainMenu;
|
||||||
//if(!isset($foundCurrent))
|
|
||||||
return $menu;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Menu() {
|
public function Menu() {
|
||||||
return $this->renderWith($this->getTemplatesWithSuffix('_Menu'));
|
return $this->renderWith($this->getTemplatesWithSuffix('_Menu'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @todo Wrap in CMSMenu instance accessor
|
||||||
|
* @return ArrayData A single menu entry (see {@link MainMenu})
|
||||||
|
*/
|
||||||
|
public function MenuCurrentItem() {
|
||||||
|
$items = $this->MainMenu();
|
||||||
|
return $items->find('LinkingMode', 'current');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a list of appropriate templates for this class, with the given suffix
|
* Return a list of appropriate templates for this class, with the given suffix
|
||||||
*/
|
*/
|
||||||
@ -1244,10 +1256,7 @@ class LeftAndMain extends Controller implements PermissionProvider {
|
|||||||
function SectionTitle() {
|
function SectionTitle() {
|
||||||
if($title = $this->stat('menu_title')) return $title;
|
if($title = $this->stat('menu_title')) return $title;
|
||||||
|
|
||||||
// Get menu - use obj() to cache it in the same place as the template engine
|
foreach($this->MainMenu() as $menuItem) {
|
||||||
$menu = $this->obj('MainMenu');
|
|
||||||
|
|
||||||
foreach($menu as $menuItem) {
|
|
||||||
if($menuItem->LinkingMode != 'link') return $menuItem->Title;
|
if($menuItem->LinkingMode != 'link') return $menuItem->Title;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -262,6 +262,8 @@ body.cms { overflow: hidden; }
|
|||||||
.cms-content-header a { color: #1556b2; }
|
.cms-content-header a { color: #1556b2; }
|
||||||
.cms-content-header .backlink span.btn-icon-back { height: 16px; }
|
.cms-content-header .backlink span.btn-icon-back { height: 16px; }
|
||||||
.cms-content-header h2 { padding: 8px 8px 0 8px; font-size: 14px; line-height: 24px; font-weight: bold; text-shadow: #bfcad2 1px 1px 0; margin: 0; display: table-cell; vertical-align: top; width: 60%; }
|
.cms-content-header h2 { padding: 8px 8px 0 8px; font-size: 14px; line-height: 24px; font-weight: bold; text-shadow: #bfcad2 1px 1px 0; margin: 0; display: table-cell; vertical-align: top; width: 60%; }
|
||||||
|
.cms-content-header h2 .section-icon { display: inline-block; vertical-align: middle; }
|
||||||
|
.cms-content-header h2 .breadcrumbs-wrapper { display: inline-block; vertical-align: middle; }
|
||||||
.cms-content-header h2 .breadcrumbs-wrapper .crumb { display: inline; line-height: 26px; padding: 0 5px; }
|
.cms-content-header h2 .breadcrumbs-wrapper .crumb { display: inline; line-height: 26px; padding: 0 5px; }
|
||||||
.cms-content-header h2 .breadcrumbs-wrapper .crumb:first-child { padding-left: 0px; }
|
.cms-content-header h2 .breadcrumbs-wrapper .crumb:first-child { padding-left: 0px; }
|
||||||
.cms-content-header h2 .breadcrumbs-wrapper .crumb:last-child { padding-right: 0px; }
|
.cms-content-header h2 .breadcrumbs-wrapper .crumb:last-child { padding-right: 0px; }
|
||||||
|
@ -117,10 +117,16 @@ body.cms {
|
|||||||
display:table-cell;
|
display:table-cell;
|
||||||
vertical-align:top;
|
vertical-align:top;
|
||||||
width:60%;
|
width:60%;
|
||||||
|
|
||||||
|
.section-icon {
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
.breadcrumbs-wrapper {
|
.breadcrumbs-wrapper {
|
||||||
// display:table;
|
display: inline-block;
|
||||||
|
vertical-align: middle;
|
||||||
.crumb {
|
.crumb {
|
||||||
// display:table-cell;
|
|
||||||
display: inline;
|
display: inline;
|
||||||
line-height:26px;
|
line-height:26px;
|
||||||
padding:0 5px;
|
padding:0 5px;
|
||||||
|
7
admin/templates/Includes/CMSSectionIcon.ss
Normal file
7
admin/templates/Includes/CMSSectionIcon.ss
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<% if ToplevelController %>
|
||||||
|
<span class="section-icon icon icon-16 icon-{$ToplevelController.MenuCurrentItem.Code.LowerCase}"></span>
|
||||||
|
<% else_if Controller %>
|
||||||
|
<span class="section-icon icon icon-16 icon-{$Controller.MenuCurrentItem.Code.LowerCase}"></span>
|
||||||
|
<% else %>
|
||||||
|
<span class="section-icon icon icon-16 icon-{$MenuCurrentItem.Code.LowerCase}"></span>
|
||||||
|
<% end_if %>
|
@ -3,21 +3,11 @@
|
|||||||
<% end_if %>
|
<% end_if %>
|
||||||
<div class="cms-content-header north">
|
<div class="cms-content-header north">
|
||||||
<div>
|
<div>
|
||||||
<% with Controller %>
|
|
||||||
<% if class=CMSFileAddController %>
|
|
||||||
<span class="section-icon icon icon-24 icon-assetadmin"></span>
|
|
||||||
<% else %>
|
|
||||||
<% with ToplevelController %>
|
|
||||||
<% if class=SecurityAdmin %>
|
|
||||||
<span class="section-icon icon icon-24 icon-securityadmin"></span>
|
|
||||||
<% end_if %>
|
|
||||||
<% end_with %>
|
|
||||||
<% end_if %>
|
|
||||||
<% end_with %>
|
|
||||||
<% include BackLink_Button %>
|
<% include BackLink_Button %>
|
||||||
|
|
||||||
<h2 id="page-title-heading">
|
<h2 id="page-title-heading">
|
||||||
<% control Controller %>
|
<% control Controller %>
|
||||||
|
<% include CMSSectionIcon %>
|
||||||
<% include CMSBreadcrumbs %>
|
<% include CMSBreadcrumbs %>
|
||||||
<% end_control %>
|
<% end_control %>
|
||||||
</h2>
|
</h2>
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
<div class="cms-content-header north">
|
<div class="cms-content-header north">
|
||||||
<div>
|
<div>
|
||||||
<h2>
|
<h2>
|
||||||
|
<% include CMSSectionIcon %>
|
||||||
<% if SectionTitle %>
|
<% if SectionTitle %>
|
||||||
$SectionTitle
|
$SectionTitle
|
||||||
<% else %>
|
<% else %>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user