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;
    }
}
Recent Tutorials
Upgrading Concrete from 8.5 to 9.x
Jun 21, 2024
By myq.

How to avoid problems upgrading from 8.5 to 9.x

How to change the default date format
May 30, 2024
By myq.

Change the format of the default date

WebOps Tutorial on Running and Upgrading a Concrete CMS Website
May 2, 2024
By myq.

Describes how to deploy, manage, and upgrade a Concrete CMS website

Using the Concrete Migration Tool Addon
Apr 27, 2024

How to use the Concrete CMS Migration Tool

Create custom Site Health tasks
Apr 19, 2024
By myq.

This tutorial will guide you through the creation of a new Site Health task

Reusing the same Express entity in multiple associations
Apr 11, 2024
By myq.

How to create and manage multiple associations in Express

Improvements?

Let us know by posting here.