Adding a menu item 5.7
This is a community-contributed tutorial. This tutorial is over a year old and may not apply to your version of Concrete CMS.
May 17, 2015
How to add a menu item (when viewing a page):
Note1: the menu items won't be displayed when viewing the dashboard. The dashboard uses its own theme and the menu items shown there are hardcoded (5.7.4)
Note2: see also https://archive.concretecms.org/community/forums/5-7-discussion/overriding-core-functions/
Add to your package controller:
use Core; // needed for Core::make('helper/concrete/ui/menu')
Add to your package controller, on_start function:
$yourIcon = array(
'icon' => 'bars',
'label' => $this->getPackageName(),
'position' => 'right',
'href' => URL::to('yourfastlink'),
'linkAttributes' => array('title'=>$this->getPackageName())
);
$menuHelper = Core::make('helper/concrete/ui/menu');
$menuHelper->addPageHeaderMenuItem('YourItem', 'YourPackage', $yourIcon);
/packages/your_package/menu_items/your_item/controller.php:
namespace Concrete\Package\YourPackage\MenuItem\YourItem;
use Page;
use Permissions;
class Controller extends \Concrete\Core\Application\UserInterface\Menu\Item\Controller { // leading '\' !!
public function displayItem()
{
// check permissions
$canView = false;
$p = Page::getByPath('/yourfastlink'); // eg. /dashboard/system/optimization/clearcache
$cpc = new Permissions($p);
if ($cpc->canViewPage()) {
$canView = true;
}
return $canView;
}
public function getMenuItemLinkElement()
{
$a = parent::getMenuItemLinkElement();
// override if you like
// check \concrete\src\Application\UserInterface\Menu\Item\Controller.php
return $a;
}
}