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
Upgrade Concrete versions 9.3.1 and 9.3.2
Sep 10, 2024
By myq.

How to get past a bug in versions 9.3.1 and 9.3.2 that prevents upgrading the Concrete core through the Dashboard

How to use Composer with Marketplace extensions
Aug 22, 2024

Composer can be used to manage third-party extensions from the marketplace

Controlling Google Tag Manager Tags Based on Concrete CMS Edit Toolbar Visibility
Aug 13, 2024

This document provides a step-by-step guide on how to control the firing of Google Tag Manager (GTM) tags based on the visibility of the Concrete CMS edit toolbar. It explains how to create a custom JavaScript variable in GTM to detect whether the edit toolbar is present on a page and how to set up a trigger that ensures GTM tags only fire when the toolbar is not visible. This setup is particularly useful for developers and marketers who want to ensure that tracking and analytics tags are not activated during content editing sessions, thereby preserving the accuracy of data collected.

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

Improvements?

Let us know by posting here.