Main menu
Previously known as Top menu and Totara menu.
Adding new menu items
Plugin developers can also add Totara menu options as follows:
First, define a class that extends \totara_core\totara\menu\item
and put it in a file in "[your-module]/classes/menu/[your-menu-item].php".
For an example, see totara/core/classes/menu/myteam.php.
You are expected to implement the following methods:
protected function get_default_title()
- Returns a string to be used from the menu item name if not customised.protected function get_default_url()
- Returns a string containing the URL to point to (absolute or relative to wwwroot if it starts with a slash).
You can choose to implement the following methods:
public function get_default_visibility()
- Returns a menu visibility constant to set the visibility when first added. Default is menu::SHOW_WHEN_REQUIRED.public function get_default_sortorder()
- Returns an integer to indicate default location within the menu when first added. Default is add to the end.protected function check_visibility()
- Returns either menu::SHOW_ALWAYS or menu::HIDE_ALWAYS. Called if visibility is set to menu::SHOW_WHEN_REQUIRED. Defaults to menu::SHOW_ALWAYS.protected function get_default_parent()
- Returns the class name of another menu item to use as the parent. Defaults to 'root' meaning top level.
Add a new file [your-module]/db/totaramenu.php
with the following:
|
See totara/core/totaramenu.php for an example.
Bump the version of your module to trigger a database upgrade. The new menu item will be detected and automatically added to the menu.
Cache invalidation
The main menu structure is cached in user session for a certain period. If an admin setting affects availability of menu item then developer should add 'totara_menu_reset_all_caches' as setting update callback.
The cache timeout in a session is designed to accommodate changes in users permissions and audiences membership.