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

Inherited from LazyOwnerAlias

List of aliases

Methods

public addMainMenuItem (string $owner, string $code, array $definition)

Dynamically add a single main menu item

Parameters
Property Description
$owner
string
$code
string
$definition
array
Returns
mixed

public addMainMenuItems (string $owner, array $definitions)

Dynamically add an array of main menu items

Parameters
Property Description
$owner
string
$definitions
array
Returns
mixed

public addQuickActionItem (string $owner, string $code, array $definition) : void

Dynamically add a single quick action item

Parameters
Property Description
$owner
string
$code
string
$definition
array
Returns
void

public addQuickActionItems (string $owner, array $definitions) : void

Dynamically add an array of quick action items

Parameters
Property Description
$owner
string
$definitions
array
Returns
void

public addSideMenuItem (string $owner, string $code, string $sideCode, array $definition) : bool

Dynamically add a single side menu item

Parameters
Property Description
$owner
string
$code
string
$sideCode
string
$definition
array
Returns
bool

public addSideMenuItems (string $owner, string $code, array $definitions)

Dynamically add an array of side menu items

Parameters
Property Description
$owner
string
$code
string
$definitions
array
Returns
mixed

public getActiveMainMenuItem () : null | MainMenuItem

Returns the currently active main menu item

Returns
null | MainMenuItem

$item Returns the item object or null.

public getContext () : mixed

Returns information about the current navigation context.

Returns
mixed

Returns an object with the following fields:

  • mainMenuCode
  • sideMenuCode
  • owner

public getContextOwner ()

Gets the navigation context owner

Returns
mixed

public getContextSidenavPartial (string $owner, string $mainMenuItemCode) : mixed

Returns the side navigation partial for a specific main menu previously registered with the registerContextSidenavPartial() method.

Parameters
Property Description
$owner
string

Specifies the navigation owner in the format Vendor/Module.

$mainMenuItemCode
string

Specifies the main menu item code.

Returns
mixed

Returns the partial name or null.

public getMainMenuItem (string $owner, string $code) : MainMenuItem

Parameters
Property Description
$owner
string
$code
string
Returns
MainMenuItem

public getQuickActionItem (string $owner, string $code) : QuickActionItem

Gets the instance of a specified quick action item.

Parameters
Property Description
$owner
string
$code
string
Returns
QuickActionItem

public isMainMenuItemActive (MainMenuItem $item) : bool

Determines if a main menu item is active.

Parameters
Property Description
$item
MainMenuItem

Specifies the item object.

Returns
bool

Returns true if the menu item is active.

public isSideMenuItemActive (SideMenuItem $item) : bool

Determines if a side menu item is active.

Parameters
Property Description
$item
SideMenuItem

Specifies the item object.

Returns
bool

Returns true if the side item is active.

public listMainMenuItems () : array

Returns a list of the main menu items.

Returns
array

public listQuickActionItems () : array

Returns a list of quick action items.

Returns
array

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.

Parameters
Property Description
$owner
null
$code
null
Returns
\SideMenuItem[]

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([...]);
});
Parameters
Property Description
$callback
callable

A callable function.

Returns
mixed

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.

Parameters
Property Description
$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.

Returns
mixed

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.
Parameters
Property Description
$owner
string

Specifies the menu items owner plugin or module in the format Author.Plugin.

$definitions
array

An array of the menu item definitions.

Returns
mixed

public registerOwnerAlias (string $owner, string $alias) : void

Register an owner alias

Parameters
Property Description
$owner
string

The owner to register an alias for. Example: Real.Owner

$alias
string

The alias to register. Example: Aliased.Owner

Returns
void

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.
Parameters
Property Description
$owner
string

Specifies the quick action items owner plugin or module in the format Author.Plugin.

$definitions
array

An array of the quick action item definitions.

Returns
void

public removeMainMenuItem (mixed $owner, mixed $code)

Removes a single main menu item

Parameters
Property Description
$owner
mixed
$code
mixed
Returns
mixed

public removeQuickActionItem (mixed $owner, mixed $code) : void

Removes a single quick action item

Parameters
Property Description
$owner
mixed
$code
mixed
Returns
void

public removeSideMenuItem (string $owner, string $code, string $sideCode) : bool

Removes a single main menu item

Parameters
Property Description
$owner
string
$code
string
$sideCode
string
Returns
bool

public removeSideMenuItems (string $owner, string $code, array $sideCodes) : void

Remove multiple side menu items

Parameters
Property Description
$owner
string
$code
string
$sideCodes
array
Returns
void

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.

Parameters
Property Description
$owner
string

Specifies the navigation owner in the format Vendor/Module

$mainMenuItemCode
string

Specifies the main menu item code

$sideMenuItemCode
string

Specifies the side menu item code

Returns
mixed

public setContextMainMenu (string $mainMenuItemCode)

Specifies a code of the main menu item in the current navigation context.

Parameters
Property Description
$mainMenuItemCode
string

Specifies the main menu item code

Returns
mixed

public setContextOwner (string $owner)

Sets the navigation context owner.

Parameters
Property Description
$owner
string

Specifies the navigation owner in the format Vendor/Module

Returns
mixed

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.

Parameters
Property Description
$sideMenuItemCode
string

Specifies the side menu item code

Returns
mixed

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).

Parameters
Property Description
$items
array

Array of MainMenuItem, SideMenuItem, or QuickActionItem objects

Returns
void

protected filterItemPermissions (Backend\Models\User $user, array $items) : array

Removes menu items from an array if the supplied user lacks permission.

Parameters
Property Description
$user

A user object

$items
array

A collection of menu items

Returns
array

The filtered menu items

protected init ()

Initialize this singleton.

Returns
mixed

protected loadItems () : void

Loads the menu items from modules and plugins

Returns
void

protected makeItemKey (string $owner, string $code) : string

Internal method to make a unique key for an item.

Parameters
Property Description
$owner
string
$code
string
Returns
string

inherited public __clone ()

Inherited from Singleton
Returns
mixed

inherited public __wakeup ()

Inherited from Singleton
Returns
mixed

inherited public static final forgetInstance ($container = null) : void

Inherited from Singleton

Forget this singleton's instance if it exists

Parameters
Property Description
$container
mixed
Returns
void

inherited public static final instance ($container = null) : static

Inherited from Singleton

Create a new instance of this singleton.

Parameters
Property Description
$container
mixed
Returns
static

inherited public static lazyRegisterOwnerAlias (string $owner, string $alias) : void

Inherited from LazyOwnerAlias

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.

Parameters
Property Description
$owner
string
$alias
string
Returns
void

inherited protected final __construct ()

Inherited from Singleton

Constructor.

Returns
mixed
Copyright © 2024 Winter CMS