Admin quick access menu

This is the dropdown administration menu added in Totara 12.

Menu structure

The code that builds the menu is located in totara/core/classes/quickaccessmenu/.

Overview

The menu is built by taking the admin tree then merging in the default menu and any user preferences that are set. For details on default menu and preferences see below.

The code to create the menu is:

$factory = \totara_core\quickaccessmenu\factory::instance($userid);
$menu = $factory->get_menu();

The process for creating the structure is first to fetch all admin nodes and create a quick access menu structure based on the nodes. Then check the 'default menu' and 'user preferences' to determine which nodes should be visible to a user.

Default menu

The default menu is build by checking all components to see if they define any menu items. To define default items a component/plugin must have a file located in <plugin>/classes/quickaccessmenu/. The structure of this file may be seen in the example for Quickaccess menu customisation.

User preferences

This includes any pages the user has add to/removed from the menu. These are serialised and stored in the quickaccess_preferences table.

Quick access menu customisation

Components can define their own items that will be added to the menu.

The settings.php file for plugin defines admin nodes:

$ADMIN->add('totara_plan', new admin_externalpage('managetemplates',
	new lang_string('managetemplates', 'totara_plan'),
	"$CFG->wwwroot/totara/plan/template/index.php",
	array('totara/plan:configureplans'),
	totara_feature_disabled('learningplans')
	)
);

In order to add an item to the quick access menu a file must be created in <plugin>/classes/quickaccessmenu/<plugin name>.php

The file must match the name of the plugin (e.g. plan.php, not totara_plan.php) to ensure it is loaded into the menu.


Example file:

<?php
namespace totara_plan\quickaccessmenu;

use \totara_core\quickaccessmenu\group;
use \totara_core\quickaccessmenu\item;

class plans implements \totara_core\quickaccessmenu\provider {

    /**
	 * Return the items that totara_plan wishes to introduce to the quick access menu.
 	 *
 	 * @return item[]
	 */
	public static function get_items(): array {
		return [
			item::from_provider(
				'managetemplates',
				group::get(group::LEARN),
				new \lang_string('learningplans', 'totara_plan'),
				6000
			)
		];
	}
}

Once this file has been created the item(s) will immediately show up in the quick access menu of all users.

Valid groups are 'platform', 'learn', 'perform' and 'configuration'.

The sort order number should be unique and may cause issues with re-ordering items if two have the same sort value.

Define default override via config.php

The quick access menu default can be overridden in config.php by setting the $CFG->defaultquickaccessmenu variable.

Here is an example:

$CFG->defaultquickaccessmenu = [
	[
		'key' => 'programmgmt',
		'group' => 'platform',
		'label' => 'Test item',
		'weight' => 1000
	],
	['key' => 'managetemplates', 'group' => 'learn', 'label' => 'Manage plan templates', 'weight' => 2000],
];

Things to note:

  • The key must be a valid admin node key
  • The platform must be one of (platform, learn, perform, configuration)

Legacy administration menu

It is possible to enable the legacy administration menu by adding the following to your config.php file:

$CFG->legacyadminsettingsmenu = true;

This will not disable the quick access menu, this will have to be done by overriding the template in your theme.