NavigationManager
Manages the backend navigation.
class Backend\Classes\NavigationManager
Traits
Trait | Description |
---|---|
LazyOwnerAlias
|
Lazy Owner Alias Adds support for statically binding owner aliases |
Singleton
|
Singleton trait. |
Properties
protected
$aliases
:
array
= []
List of owner aliases. ['Aliased.Owner' => 'Real.Owner']
protected
$callbacks
:
array
= []
Cache of registration callbacks.
protected $contextMainMenuItemCode : mixed
protected $contextOwner : mixed
protected $contextSideMenuItemCode : mixed
protected
$contextSidenavPartials
:
mixed
= []
protected $items : \MainMenuItem[]
List of registered items.
protected $pluginManager : PluginManager
protected $quickActions : \QuickActionItem[]
List of registered quick actions.
inherited
protected
static
$lazyAliases
:
array
= []
List of aliases
Methods
public addMainMenuItem (string $owner, string $code, array $definition)
Dynamically add a single main menu item
Property | Type | Description |
---|---|---|
$owner | string |
string
|
$code | string |
string
|
$definition | array |
array
|
public addMainMenuItems (string $owner, array $definitions)
Dynamically add an array of main menu items
Property | Type | Description |
---|---|---|
$owner | string |
string
|
$definitions | array |
array
|
public addQuickActionItem (string $owner, string $code, array $definition) : void
Dynamically add a single quick action item
Property | Type | Description |
---|---|---|
$owner | string |
string
|
$code | string |
string
|
$definition | array |
array
|
public addQuickActionItems (string $owner, array $definitions) : void
Dynamically add an array of quick action items
Property | Type | Description |
---|---|---|
$owner | string |
string
|
$definitions | array |
array
|
public addSideMenuItem (string $owner, string $code, string $sideCode, array $definition) : bool
Dynamically add a single side menu item
Property | Type | Description |
---|---|---|
$owner | string |
string
|
$code | string |
string
|
$sideCode | string |
string
|
$definition | array |
array
|
public addSideMenuItems (string $owner, string $code, array $definitions)
Dynamically add an array of side menu items
Property | Type | Description |
---|---|---|
$owner | string |
string
|
$code | string |
string
|
$definitions | array |
array
|
public getActiveMainMenuItem () : null | MainMenuItem
Returns the currently active main menu item
$item Returns the item object or null.
public getContext () : mixed
Returns information about the current navigation context.
Returns an object with the following fields:
- mainMenuCode
- sideMenuCode
- owner
public getContextOwner ()
Gets the navigation context owner
public getContextSidenavPartial (string $owner, string $mainMenuItemCode) : mixed
Returns the side navigation partial for a specific main menu previously registered with the registerContextSidenavPartial() method.
Property | Type | Description |
---|---|---|
$owner | string |
string
Specifies the navigation owner in the format Vendor/Module. |
$mainMenuItemCode | string |
string
Specifies the main menu item code. |
Returns the partial name or null.
public getMainMenuItem (string $owner, string $code) : MainMenuItem
Property | Type | Description |
---|---|---|
$owner | string |
string
|
$code | string |
string
|
public getQuickActionItem (string $owner, string $code) : QuickActionItem
Gets the instance of a specified quick action item.
Property | Type | Description |
---|---|---|
$owner | string |
string
|
$code | string |
string
|
public isMainMenuItemActive (MainMenuItem $item) : bool
Determines if a main menu item is active.
Property | Type | Description |
---|---|---|
$item | MainMenuItem |
MainMenuItem
Specifies the item object. |
Returns true if the menu item is active.
public isSideMenuItemActive (SideMenuItem $item) : bool
Determines if a side menu item is active.
Property | Type | Description |
---|---|---|
$item | SideMenuItem |
SideMenuItem
Specifies the item object. |
Returns true if the side item is active.
public listMainMenuItems () : array
Returns a list of the main menu items.
public listQuickActionItems () : array
Returns a list of quick action items.
public
listSideMenuItems (null $owner = null
, null $code = null
)
: \SideMenuItem[]
Returns a list of side menu items for the currently active main menu item.
The currently active main menu item is set with the setContext methods.
Property | Type | Description |
---|---|---|
$owner | null |
null
|
$code | null |
null
|
public registerCallback (callable $callback)
Registers a callback function that defines menu items.
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([...]);
});
Property | Type | Description |
---|---|---|
$callback | callable |
callable
A callable function. |
public registerContextSidenavPartial (string $owner, string $mainMenuItemCode, string $partial)
Registers a special side navigation partial for a specific main menu.
The sidenav partial replaces the standard side navigation.
Property | Type | Description |
---|---|---|
$owner | string |
string
Specifies the navigation owner in the format Vendor/Module. |
$mainMenuItemCode | string |
string
Specifies the main menu item code. |
$partial | string |
string
Specifies the partial name. |
public registerMenuItems (string $owner, array $definitions)
Registers the back-end menu items.
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.
Property | Type | Description |
---|---|---|
$owner | string |
string
Specifies the menu items owner plugin or module in the format Author.Plugin. |
$definitions | array |
array
An array of the menu item definitions. |
public registerOwnerAlias (string $owner, string $alias) : void
Register an owner alias
Property | Type | Description |
---|---|---|
$owner | string |
string
The owner to register an alias for. Example: Real.Owner |
$alias | string |
string
The alias to register. Example: Aliased.Owner |
public registerQuickActions (string $owner, array $definitions) : void
Registers quick actions in the main navigation.
Quick actions are single purpose links displayed to the left of the user menu in the backend main navigation.
The argument is an array of the quick action items. The array keys represent the quick action item codes, specific for the plugin/module. Each element in the array should be an associative array with the following keys:
- label - specifies the action label localization string key, used as a tooltip, required.
- icon - an icon name from the Font Awesome icon collection, required if iconSvg is unspecified.
- iconSvg - a custom SVG icon to use for the icon, required if icon is unspecified.
- url - the back-end relative URL the quick action 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.
Property | Type | Description |
---|---|---|
$owner | string |
string
Specifies the quick action items owner plugin or module in the format Author.Plugin. |
$definitions | array |
array
An array of the quick action item definitions. |
public removeMainMenuItem (mixed $owner, mixed $code)
Removes a single main menu item
Property | Type | Description |
---|---|---|
$owner | mixed |
mixed
|
$code | mixed |
mixed
|
public removeQuickActionItem (mixed $owner, mixed $code) : void
Removes a single quick action item
Property | Type | Description |
---|---|---|
$owner | mixed |
mixed
|
$code | mixed |
mixed
|
public removeSideMenuItem (string $owner, string $code, string $sideCode) : bool
Removes a single main menu item
Property | Type | Description |
---|---|---|
$owner | string |
string
|
$code | string |
string
|
$sideCode | string |
string
|
public removeSideMenuItems (string $owner, string $code, array $sideCodes) : void
Remove multiple side menu items
Property | Type | Description |
---|---|---|
$owner | string |
string
|
$code | string |
string
|
$sideCodes | array |
array
|
public
setContext (string $owner, string $mainMenuItemCode, string $sideMenuItemCode = null
)
Sets the navigation context.
The function sets the navigation owner, main menu item code and the side menu item code.
Property | Type | Description |
---|---|---|
$owner | string |
string
Specifies the navigation owner in the format Vendor/Module |
$mainMenuItemCode | string |
string
Specifies the main menu item code |
$sideMenuItemCode | string |
string
Specifies the side menu item code |
public setContextMainMenu (string $mainMenuItemCode)
Specifies a code of the main menu item in the current navigation context.
Property | Type | Description |
---|---|---|
$mainMenuItemCode | string |
string
Specifies the main menu item code |
public setContextOwner (string $owner)
Sets the navigation context owner.
Property | Type | Description |
---|---|---|
$owner | string |
string
Specifies the navigation owner in the format Vendor/Module |
public setContextSideMenu (string $sideMenuItemCode)
Specifies a code of the side menu item in the current navigation context.
If the code is set to TRUE, the first item will be flagged as active.
Property | Type | Description |
---|---|---|
$sideMenuItemCode | string |
string
Specifies the side menu item code |
protected applyDefaultOrders (array $items) : void
Apply incremental default orders to items with the explicit auto-order value (-1) or that have invalid order values (non-integer).
Property | Type | Description |
---|---|---|
$items | array |
array
Array of MainMenuItem, SideMenuItem, or QuickActionItem objects |
protected filterItemPermissions (Backend\Models\User $user, array $items) : array
Removes menu items from an array if the supplied user lacks permission.
Property | Type | Description |
---|---|---|
$user | Backend\Models\User |
A user object |
$items | array |
array
A collection of menu items |
The filtered menu items
protected init ()
Initialize this singleton.
protected loadItems () : void
Loads the menu items from modules and plugins
protected makeItemKey (string $owner, string $code) : string
Internal method to make a unique key for an item.
Property | Type | Description |
---|---|---|
$owner | string |
string
|
$code | string |
string
|
inherited public __clone ()
inherited public __wakeup ()
inherited
public
static
final
forgetInstance ($container = null
)
: void
Forget this singleton's instance if it exists
Property | Type | Description |
---|---|---|
$container | mixed |
mixed
|
inherited
public
static
final
instance ($container = null
)
: static
Create a new instance of this singleton.
Property | Type | Description |
---|---|---|
$container | mixed |
mixed
|
inherited public static lazyRegisterOwnerAlias (string $owner, string $alias) : void
Binds the alias of an owner to the lazy alias list. This allows us to bind aliases
prior to init() which is necessary to do before to PluginManager
being registered.
Property | Type | Description |
---|---|---|
$owner | string |
string
|
$alias | string |
string
|
inherited protected final __construct ()
Constructor.