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
How to Automate the Copyright Year
Dec 27, 2024

Learn how to keep your website's copyright year updated automatically in Concrete CMS.

How to change the path of a group of pages
Dec 23, 2024
By myq.

Change the canonical path without breaking things

Bi-directional Express associations
Dec 18, 2024
By myq.

Set up associations between Express entries in both directions

Display Express Data Across Multiple Sites
Dec 17, 2024
By myq.

A guide to configuring Express entities and the Express Entry List block to ensure proper data display across multiple sites.

Customize locale icons
Oct 29, 2024
By myq.

How to customize locale (language region) flags

Concrete CMS Caching Guide
Oct 16, 2024

An overview of types of caching in Concrete and considerations when using them.

Improvements?

Let us know by posting here.