ENHANCEMENT Section icons in CMS (#7269)

This commit is contained in:
Ingo Schommer 2012-05-03 13:49:19 +02:00
parent 0d1e4cece5
commit 4029f96728
6 changed files with 83 additions and 68 deletions

View File

@ -437,75 +437,87 @@ class LeftAndMain extends Controller implements PermissionProvider {
* Returns the main menu of the CMS. This is also used by init()
* to work out which sections the user has access to.
*
* @param Boolean
* @return SS_List
*/
public function MainMenu() {
// Don't accidentally return a menu if you're not logged in - it's used to determine access.
if(!Member::currentUser()) return new ArrayList();
public function MainMenu($cached = true) {
if(!isset($this->_cache_MainMenu) || !$cached) {
// 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
$menu = new ArrayList();
$menuItems = CMSMenu::get_viewable_menu_items();
if($menuItems) {
foreach($menuItems as $code => $menuItem) {
// alternate permission checks (in addition to LeftAndMain->canView())
if(
isset($menuItem->controller)
&& $this->hasMethod('alternateMenuDisplayCheck')
&& !$this->alternateMenuDisplayCheck($menuItem->controller)
) {
continue;
}
// Encode into DO set
$menu = new ArrayList();
$menuItems = CMSMenu::get_viewable_menu_items();
if($menuItems) {
foreach($menuItems as $code => $menuItem) {
// alternate permission checks (in addition to LeftAndMain->canView())
if(
isset($menuItem->controller)
&& $this->hasMethod('alternateMenuDisplayCheck')
&& !$this->alternateMenuDisplayCheck($menuItem->controller)
) {
continue;
}
$linkingmode = "link";
if($menuItem->controller && get_class($this) == $menuItem->controller) {
$linkingmode = "current";
} else if(strpos($this->Link(), $menuItem->url) !== false) {
if($this->Link() == $menuItem->url) {
$linkingmode = "link";
if($menuItem->controller && get_class($this) == $menuItem->controller) {
$linkingmode = "current";
// 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').'/') {
} else 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}
} else if(singleton($menuItem->controller)->stat('url_segment') == '') {
if($this->Link() == $this->stat('url_base').'/') {
$linkingmode = "current";
}
} else {
$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
//if(!isset($foundCurrent))
return $menu;
return $this->_cache_MainMenu;
}
public function 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
*/
@ -1244,10 +1256,7 @@ class LeftAndMain extends Controller implements PermissionProvider {
function SectionTitle() {
if($title = $this->stat('menu_title')) return $title;
// Get menu - use obj() to cache it in the same place as the template engine
$menu = $this->obj('MainMenu');
foreach($menu as $menuItem) {
foreach($this->MainMenu() as $menuItem) {
if($menuItem->LinkingMode != 'link') return $menuItem->Title;
}
}

View File

@ -262,6 +262,8 @@ body.cms { overflow: hidden; }
.cms-content-header a { color: #1556b2; }
.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 .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:first-child { padding-left: 0px; }
.cms-content-header h2 .breadcrumbs-wrapper .crumb:last-child { padding-right: 0px; }

View File

@ -117,10 +117,16 @@ body.cms {
display:table-cell;
vertical-align:top;
width:60%;
.section-icon {
display: inline-block;
vertical-align: middle;
}
.breadcrumbs-wrapper {
// display:table;
display: inline-block;
vertical-align: middle;
.crumb {
// display:table-cell;
display: inline;
line-height:26px;
padding:0 5px;

View 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 %>

View File

@ -3,21 +3,11 @@
<% end_if %>
<div class="cms-content-header north">
<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 %>
<h2 id="page-title-heading">
<% control Controller %>
<% include CMSSectionIcon %>
<% include CMSBreadcrumbs %>
<% end_control %>
</h2>

View File

@ -3,6 +3,7 @@
<div class="cms-content-header north">
<div>
<h2>
<% include CMSSectionIcon %>
<% if SectionTitle %>
$SectionTitle
<% else %>