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 http://www.concrete5.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;
    }
}
Loading Conversation