interface MenuLinkManagerInterface implements PluginManagerInterface (View source)

Defines an interface for managing menu links and storing their definitions.

Menu link managers support both automatic plugin definition discovery and manually maintaining plugin definitions.

MenuLinkManagerInterface::updateDefinition() can be used to update a single menu link's definition and pass this onto the menu storage without requiring a full MenuLinkManagerInterface::rebuild().

Implementations that do not use automatic discovery should call MenuLinkManagerInterface::addDefinition() or MenuLinkManagerInterface::removeDefinition() when they add or remove links, and MenuLinkManagerInterface::updateDefinition() to update links they have already defined.

Methods

mixed
getDefinition(string $plugin_id, bool $exception_on_invalid = TRUE)

Gets a specific plugin definition.

array
getDefinitions()

Gets the definition of all plugins for this type.

bool
hasDefinition(string $plugin_id)

Indicates if a specific plugin definition exists.

object
createInstance(string $plugin_id, array $configuration = [])

Creates a pre-configured instance of a plugin.

object|false
getInstance(array $options)

Gets a preconfigured instance of a plugin.

rebuild()

Triggers discovery, save, and cleanup of discovered links.

deleteLinksInMenu(string $menu_name)

Deletes all links having a certain menu name.

removeDefinition(string $id, bool $persist = TRUE)

Removes a single link definition from the menu tree storage.

loadLinksByRoute(string $route_name, array $route_parameters = [], string $menu_name = NULL)

Loads multiple plugin instances based on route.

addDefinition(string $id, array $definition)

Adds a new menu link definition to the menu tree storage.

updateDefinition(string $id, array $new_definition_values, bool $persist = TRUE)

Updates the values for a menu link definition in the menu tree storage.

resetLink(string $id)

Resets the values for a menu link based on the values found by discovery.

int
countMenuLinks(string $menu_name = NULL)

Counts the total number of menu links.

array
getParentIds(string $id)

Loads all parent link IDs of a given menu link.

array
getChildIds(string $id)

Loads all child link IDs of a given menu link, regardless of visibility.

bool
menuNameInUse(string $menu_name)

Determines if any links use a given menu name.

resetDefinitions()

Resets any local definition cache. Used for testing.

Details

mixed getDefinition(string $plugin_id, bool $exception_on_invalid = TRUE)

Gets a specific plugin definition.

Parameters

string $plugin_id

A plugin id.

bool $exception_on_invalid

(optional) If TRUE, an invalid plugin ID will throw an exception.

Return Value

mixed

A plugin definition, or NULL if the plugin ID is invalid and $exception_on_invalid is FALSE.

Exceptions

PluginNotFoundException

array getDefinitions()

Gets the definition of all plugins for this type.

Return Value

array

An array of plugin definitions (empty array if no definitions were found). Keys are plugin IDs.

See also

FilteredPluginManagerInterface::getFilteredDefinitions

bool hasDefinition(string $plugin_id)

Indicates if a specific plugin definition exists.

Parameters

string $plugin_id

A plugin ID.

Return Value

bool

TRUE if the definition exists, FALSE otherwise.

object createInstance(string $plugin_id, array $configuration = [])

Creates a pre-configured instance of a plugin.

Parameters

string $plugin_id

The ID of the plugin being instantiated.

array $configuration

An array of configuration relevant to the plugin instance.

Return Value

object

A fully configured plugin instance.

Exceptions

PluginException

object|false getInstance(array $options)

Gets a preconfigured instance of a plugin.

Parameters

array $options

An array of options that can be used to determine a suitable plugin to instantiate and how to configure it.

Return Value

object|false

A fully configured plugin instance. The interface of the plugin instance will depend on the plugin type. If no instance can be retrieved, FALSE will be returned.

rebuild()

Triggers discovery, save, and cleanup of discovered links.

deleteLinksInMenu(string $menu_name)

Deletes all links having a certain menu name.

If a link is not deletable but is resettable, the link will be reset to have its original menu name, under the assumption that the original menu is not the one we are deleting it from. Note that when resetting, if the original menu name is the same as the menu name passed to this method, the link will not be moved or deleted.

Parameters

string $menu_name

The name of the menu whose links will be deleted or reset.

removeDefinition(string $id, bool $persist = TRUE)

Removes a single link definition from the menu tree storage.

This is used for plugins not found through discovery to remove definitions.

Parameters

string $id

The menu link plugin ID.

bool $persist

If TRUE, this method will attempt to persist the deletion from any external storage by invoking MenuLinkInterface::deleteLink() on the plugin that is being deleted.

Exceptions

PluginException

MenuLinkInterface[] loadLinksByRoute(string $route_name, array $route_parameters = [], string $menu_name = NULL)

Loads multiple plugin instances based on route.

Parameters

string $route_name

The route name.

array $route_parameters

(optional) The route parameters. Defaults to an empty array.

string $menu_name

(optional) Restricts the found links to just those in the named menu.

Return Value

MenuLinkInterface[]

An array of instances keyed by plugin ID.

MenuLinkInterface addDefinition(string $id, array $definition)

Adds a new menu link definition to the menu tree storage.

Use this function when you know there is no entry in the tree. This is used for plugins not found through discovery to add new definitions.

Parameters

string $id

The plugin ID for the new menu link definition that is being added.

array $definition

The values of the link definition.

Return Value

MenuLinkInterface

A plugin instance created using the newly added definition.

Exceptions

PluginException

MenuLinkInterface updateDefinition(string $id, array $new_definition_values, bool $persist = TRUE)

Updates the values for a menu link definition in the menu tree storage.

This will update the definition for a discovered menu link without the need for a full rebuild. It is also used for plugins not found through discovery to update definitions.

Parameters

string $id

The menu link plugin ID.

array $new_definition_values

The new values for the link definition. This will usually be just a subset of the plugin definition.

bool $persist

TRUE to also have the link instance itself persist the changed values to any additional storage by invoking MenuLinkInterface::updateDefinition() on the plugin that is being updated.

Return Value

MenuLinkInterface

A plugin instance created using the updated definition.

Exceptions

PluginException

Resets the values for a menu link based on the values found by discovery.

Parameters

string $id

The menu link plugin ID.

Return Value

MenuLinkInterface

The menu link instance after being reset.

Exceptions

PluginException

Counts the total number of menu links.

Parameters

string $menu_name

(optional) The menu name to count by. Defaults to all menus.

Return Value

int

The number of menu links in the named menu, or in all menus if the menu name is NULL.

array getParentIds(string $id)

Loads all parent link IDs of a given menu link.

This method is very similar to getActiveTrailIds() but allows the link to be specified rather than being discovered based on the menu name and request. This method is mostly useful for testing.

Parameters

string $id

The menu link plugin ID.

Return Value

array

An ordered array of IDs representing the path to the root of the tree. The first element of the array will be equal to $id, unless $id is not valid, in which case the return value will be NULL.

array getChildIds(string $id)

Loads all child link IDs of a given menu link, regardless of visibility.

This method is mostly useful for testing.

Parameters

string $id

The menu link plugin ID.

Return Value

array

An unordered array of IDs representing the IDs of all children, or NULL if the ID is invalid.

bool menuNameInUse(string $menu_name)

Determines if any links use a given menu name.

Parameters

string $menu_name

The menu name.

Return Value

bool

TRUE if any links are present in the named menu, FALSE otherwise.

resetDefinitions()

Resets any local definition cache. Used for testing.