MenuLinkManager
class MenuLinkManager implements MenuLinkManagerInterface (View source)
Manages discovery, instantiation, and tree building of menu link plugins.
This manager finds plugins that are rendered as menu links.
Properties
| protected array | $defaults | Provides some default values for the definition of all menu link plugins. |
|
| protected DiscoveryInterface | $discovery | The object that discovers plugins managed by this manager. |
|
| protected FactoryInterface | $factory | The object that instantiates plugins managed by this manager. |
|
| protected MenuTreeStorageInterface | $treeStorage | The menu link tree storage. |
|
| protected StaticMenuLinkOverridesInterface | $overrides | Service providing overrides for static links. |
|
| protected ModuleHandlerInterface | $moduleHandler | The module handler. |
Methods
Constructs a \Drupal\Core\Menu\MenuLinkManager object.
Performs extra processing on plugin definitions.
Gets the plugin discovery.
Gets the plugin factory.
Gets the definition of all plugins for this type.
Triggers discovery, save, and cleanup of discovered links.
Gets a specific plugin definition.
Indicates if a specific plugin definition exists.
Returns a pre-configured menu link plugin instance.
Gets a preconfigured instance of a plugin.
Deletes all links having a certain menu name.
Removes a single link definition from the menu tree storage.
Determines if any links use a given menu name.
Counts the total number of menu links.
Loads all parent link IDs of a given menu link.
Loads all child link IDs of a given menu link, regardless of visibility.
Loads multiple plugin instances based on route.
Adds a new menu link definition to the menu tree storage.
Updates the values for a menu link definition in the menu tree storage.
Resets the values for a menu link based on the values found by discovery.
Resets any local definition cache. Used for testing.
Details
__construct(MenuTreeStorageInterface $tree_storage, StaticMenuLinkOverridesInterface $overrides, ModuleHandlerInterface $module_handler)
Constructs a \Drupal\Core\Menu\MenuLinkManager object.
protected
processDefinition(array $definition, $plugin_id)
Performs extra processing on plugin definitions.
By default we add defaults for the type to the definition. If a type has additional processing logic, the logic can be added by replacing or extending this method.
protected DiscoveryInterface
getDiscovery()
Gets the plugin discovery.
protected FactoryInterface
getFactory()
Gets the plugin factory.
array
getDefinitions()
Gets the definition of all plugins for this type.
rebuild()
Triggers discovery, save, and cleanup of discovered links.
mixed
getDefinition(string $plugin_id, bool $exception_on_invalid = TRUE)
Gets a specific plugin definition.
bool
hasDefinition(string $plugin_id)
Indicates if a specific plugin definition exists.
object
createInstance(string $plugin_id, array $configuration = [])
Returns a pre-configured menu link plugin instance.
object|false
getInstance(array $options)
Gets a preconfigured instance of a plugin.
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.
protected
deleteInstance(MenuLinkInterface $instance, bool $persist)
Deletes a specific instance.
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.
bool
menuNameInUse(string $menu_name)
Determines if any links use a given menu name.
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.
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.
array
getChildIds(string $id)
Loads all child link IDs of a given menu link, regardless of visibility.
This method is mostly useful for testing.
MenuLinkInterface[]
loadLinksByRoute(string $route_name, array $route_parameters = [], string $menu_name = NULL)
Loads multiple plugin instances based on route.
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.
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.
MenuLinkInterface
resetLink(string $id)
Resets the values for a menu link based on the values found by discovery.
protected MenuLinkInterface
resetInstance(MenuLinkInterface $instance)
Resets the menu link to its default settings.
resetDefinitions()
Resets any local definition cache. Used for testing.