NavigationManager
in package
Uses
Singleton
Manages the backend navigation.
Tags
Table of Contents
- $callbacks : array<string|int, mixed>
- $contextMainMenuItemCode : mixed
- $contextOwner : mixed
- $contextSideMenuItemCode : mixed
- $contextSidenavPartials : mixed
- $instance : mixed
- $items : array<string|int, MainMenuItem>
- $pluginManager : PluginManager
- __clone() : mixed
- __wakeup() : mixed
- addMainMenuItem() : mixed
- Dynamically add a single main menu item
- addMainMenuItems() : mixed
- Dynamically add an array of main menu items
- addSideMenuItem() : bool
- Dynamically add a single side menu item
- addSideMenuItems() : mixed
- Dynamically add an array of side menu items
- forgetInstance() : mixed
- Forget this singleton's instance if it exists
- getActiveMainMenuItem() : null|MainMenuItem
- Returns the currently active main menu item
- getContext() : mixed
- Returns information about the current navigation context.
- getContextSidenavPartial() : mixed
- Returns the side navigation partial for a specific main menu previously registered with the registerContextSidenavPartial() method.
- getMainMenuItem() : MainMenuItem
- instance() : mixed
- Create a new instance of this singleton.
- isMainMenuItemActive() : bool
- Determines if a main menu item is active.
- isSideMenuItemActive() : bool
- Determines if a side menu item is active.
- listMainMenuItems() : array<string|int, mixed>
- Returns a list of the main menu items.
- listSideMenuItems() : array<string|int, SideMenuItem>
- Returns a list of side menu items for the currently active main menu item.
- registerCallback() : mixed
- Registers a callback function that defines menu items.
- registerContextSidenavPartial() : mixed
- Registers a special side navigation partial for a specific main menu.
- registerMenuItems() : mixed
- Registers the back-end menu items.
- removeMainMenuItem() : mixed
- Removes a single main menu item
- removeSideMenuItem() : bool
- Removes a single main menu item
- setContext() : mixed
- Sets the navigation context.
- setContextMainMenu() : mixed
- Specifies a code of the main menu item in the current navigation context.
- setContextOwner() : mixed
- Sets the navigation context.
- setContextSideMenu() : mixed
- Specifies a code of the side menu item in the current navigation context.
- __construct() : mixed
- Constructor.
- filterItemPermissions() : array<string|int, mixed>
- Removes menu items from an array if the supplied user lacks permission.
- init() : mixed
- Initialize this singleton.
- loadItems() : void
- Loads the menu items from modules and plugins
- makeItemKey() : string
- Internal method to make a unique key for an item.
Properties
$callbacks
protected
array<string|int, mixed>
$callbacks
= []
Cache of registration callbacks.
$contextMainMenuItemCode
protected
mixed
$contextMainMenuItemCode
$contextOwner
protected
mixed
$contextOwner
$contextSideMenuItemCode
protected
mixed
$contextSideMenuItemCode
$contextSidenavPartials
protected
mixed
$contextSidenavPartials
= []
$instance
protected
static mixed
$instance
$items
protected
array<string|int, MainMenuItem>
$items
List of registered items.
$pluginManager
protected
PluginManager
$pluginManager
Methods
__clone()
public
__clone() : mixed
Return values
mixed —__wakeup()
public
__wakeup() : mixed
Return values
mixed —addMainMenuItem()
Dynamically add a single main menu item
public
addMainMenuItem(string $owner, string $code, array<string|int, mixed> $definition) : mixed
Parameters
- $owner : string
- $code : string
- $definition : array<string|int, mixed>
Return values
mixed —addMainMenuItems()
Dynamically add an array of main menu items
public
addMainMenuItems(string $owner, array<string|int, mixed> $definitions) : mixed
Parameters
- $owner : string
- $definitions : array<string|int, mixed>
Return values
mixed —addSideMenuItem()
Dynamically add a single side menu item
public
addSideMenuItem(string $owner, string $code, string $sideCode, array<string|int, mixed> $definition) : bool
Parameters
- $owner : string
- $code : string
- $sideCode : string
- $definition : array<string|int, mixed>
Return values
bool —addSideMenuItems()
Dynamically add an array of side menu items
public
addSideMenuItems(string $owner, string $code, array<string|int, mixed> $definitions) : mixed
Parameters
- $owner : string
- $code : string
- $definitions : array<string|int, mixed>
Return values
mixed —forgetInstance()
Forget this singleton's instance if it exists
public
final static forgetInstance() : mixed
Return values
mixed —getActiveMainMenuItem()
Returns the currently active main menu item
public
getActiveMainMenuItem() : null|MainMenuItem
Tags
Return values
null|MainMenuItem —$item Returns the item object or null.
getContext()
Returns information about the current navigation context.
public
getContext() : mixed
Return values
mixed —Returns an object with the following fields:
- mainMenuCode
- sideMenuCode
- owner
getContextSidenavPartial()
Returns the side navigation partial for a specific main menu previously registered with the registerContextSidenavPartial() method.
public
getContextSidenavPartial(string $owner, string $mainMenuItemCode) : mixed
Parameters
- $owner : string
-
Specifies the navigation owner in the format Vendor/Module.
- $mainMenuItemCode : string
-
Specifies the main menu item code.
Return values
mixed —Returns the partial name or null.
getMainMenuItem()
public
getMainMenuItem(string $owner, string $code) : MainMenuItem
Parameters
- $owner : string
- $code : string
Tags
Return values
MainMenuItem —instance()
Create a new instance of this singleton.
public
final static instance() : mixed
Return values
mixed —isMainMenuItemActive()
Determines if a main menu item is active.
public
isMainMenuItemActive(MainMenuItem $item) : bool
Parameters
- $item : MainMenuItem
-
Specifies the item object.
Return values
bool —Returns true if the menu item is active.
isSideMenuItemActive()
Determines if a side menu item is active.
public
isSideMenuItemActive(SideMenuItem $item) : bool
Parameters
- $item : SideMenuItem
-
Specifies the item object.
Return values
bool —Returns true if the side item is active.
listMainMenuItems()
Returns a list of the main menu items.
public
listMainMenuItems() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —listSideMenuItems()
Returns a list of side menu items for the currently active main menu item.
public
listSideMenuItems([null $owner = null ][, null $code = null ]) : array<string|int, SideMenuItem>
The currently active main menu item is set with the setContext methods.
Parameters
- $owner : null = null
- $code : null = null
Tags
Return values
array<string|int, SideMenuItem> —registerCallback()
Registers a callback function that defines menu items.
public
registerCallback(callable $callback) : mixed
The callback function should register menu items by calling the manager's
registerMenuItems method. The manager instance is passed to the callback
function as an argument. Usage:
BackendMenu::registerCallback(function ($manager) {
$manager->registerMenuItems([...]);
});
Parameters
- $callback : callable
-
A callable function.
Return values
mixed —registerContextSidenavPartial()
Registers a special side navigation partial for a specific main menu.
public
registerContextSidenavPartial(string $owner, string $mainMenuItemCode, string $partial) : mixed
The sidenav partial replaces the standard side navigation.
Parameters
- $owner : string
-
Specifies the navigation owner in the format Vendor/Module.
- $mainMenuItemCode : string
-
Specifies the main menu item code.
- $partial : string
-
Specifies the partial name.
Return values
mixed —registerMenuItems()
Registers the back-end menu items.
public
registerMenuItems(string $owner, array<string|int, mixed> $definitions) : mixed
The argument is an array of the main menu items. The array keys represent the menu item codes, specific for the plugin/module. Each element in the array should be an associative array with the following keys:
- label - specifies the menu label localization string key, required.
- icon - an icon name from the Font Awesome icon collection, required.
- url - the back-end relative URL the menu item should point to, required.
- permissions - an array of permissions the back-end user should have, optional. The item will be displayed if the user has any of the specified permissions.
- order - a position of the item in the menu, optional.
- counter - an optional numeric value to output near the menu icon. The value should be a number or a callable returning a number.
- counterLabel - an optional string value to describe the numeric reference in counter.
- sideMenu - an array of side menu items, optional. If provided, the array items
should represent the side menu item code, and each value should be an associative
array with the following keys:
- label - specifies the menu label localization string key, required.
- icon - an icon name from the Font Awesome icon collection, required.
- url - the back-end relative URL the menu item should point to, required.
- attributes - an array of attributes and values to apply to the menu item, optional.
- permissions - an array of permissions the back-end user should have, optional.
- counter - an optional numeric value to output near the menu icon. The value should be a number or a callable returning a number.
- counterLabel - an optional string value to describe the numeric reference in counter.
- badge - an optional string value to output near the menu icon. The value should be a string. This value will override the counter if set.
Parameters
- $owner : string
-
Specifies the menu items owner plugin or module in the format Author.Plugin.
- $definitions : array<string|int, mixed>
-
An array of the menu item definitions.
Tags
Return values
mixed —removeMainMenuItem()
Removes a single main menu item
public
removeMainMenuItem( $owner, $code) : mixed
Parameters
Return values
mixed —removeSideMenuItem()
Removes a single main menu item
public
removeSideMenuItem(string $owner, string $code, string $sideCode) : bool
Parameters
- $owner : string
- $code : string
- $sideCode : string
Return values
bool —setContext()
Sets the navigation context.
public
setContext(string $owner, string $mainMenuItemCode[, string $sideMenuItemCode = null ]) : mixed
The function sets the navigation owner, main menu item code and the side menu item code.
Parameters
- $owner : string
-
Specifies the navigation owner in the format Vendor/Module
- $mainMenuItemCode : string
-
Specifies the main menu item code
- $sideMenuItemCode : string = null
-
Specifies the side menu item code
Return values
mixed —setContextMainMenu()
Specifies a code of the main menu item in the current navigation context.
public
setContextMainMenu(string $mainMenuItemCode) : mixed
Parameters
- $mainMenuItemCode : string
-
Specifies the main menu item code
Return values
mixed —setContextOwner()
Sets the navigation context.
public
setContextOwner(string $owner) : mixed
The function sets the navigation owner.
Parameters
- $owner : string
-
Specifies the navigation owner in the format Vendor/Module
Return values
mixed —setContextSideMenu()
Specifies a code of the side menu item in the current navigation context.
public
setContextSideMenu(string $sideMenuItemCode) : mixed
If the code is set to TRUE, the first item will be flagged as active.
Parameters
- $sideMenuItemCode : string
-
Specifies the side menu item code
Return values
mixed —__construct()
Constructor.
protected
final __construct() : mixed
Return values
mixed —filterItemPermissions()
Removes menu items from an array if the supplied user lacks permission.
protected
filterItemPermissions(User $user, array<string|int, MainMenuItem>|array<string|int, SideMenuItem> $items) : array<string|int, mixed>
Parameters
- $user : User
-
A user object
- $items : array<string|int, MainMenuItem>|array<string|int, SideMenuItem>
-
A collection of menu items
Return values
array<string|int, mixed> —The filtered menu items
init()
Initialize this singleton.
protected
init() : mixed
Return values
mixed —loadItems()
Loads the menu items from modules and plugins
protected
loadItems() : void
Tags
Return values
void —makeItemKey()
Internal method to make a unique key for an item.
protected
makeItemKey(string $owner, string $code) : string
Parameters
- $owner : string
- $code : string