Drupal 8  8.0.2
MenuLinkManager Class Reference
Inheritance diagram for MenuLinkManager:

Public Member Functions

 __construct (MenuTreeStorageInterface $tree_storage, StaticMenuLinkOverridesInterface $overrides, ModuleHandlerInterface $module_handler)
 
 getDefinitions ()
 
 rebuild ()
 
 getDefinition ($plugin_id, $exception_on_invalid=TRUE)
 
 hasDefinition ($plugin_id)
 
 createInstance ($plugin_id, array $configuration=array())
 
 getInstance (array $options)
 
 deleteLinksInMenu ($menu_name)
 
 removeDefinition ($id, $persist=TRUE)
 
 menuNameInUse ($menu_name)
 
 countMenuLinks ($menu_name=NULL)
 
 getParentIds ($id)
 
 getChildIds ($id)
 
 loadLinksByRoute ($route_name, array $route_parameters=array(), $menu_name=NULL)
 
 addDefinition ($id, array $definition)
 
 updateDefinition ($id, array $new_definition_values, $persist=TRUE)
 
 resetLink ($id)
 
 resetDefinitions ()
 

Protected Member Functions

 processDefinition (array &$definition, $plugin_id)
 
 getDiscovery ()
 
 getFactory ()
 
 deleteInstance (MenuLinkInterface $instance, $persist)
 
 resetInstance (MenuLinkInterface $instance)
 

Protected Attributes

 $defaults
 
 $discovery
 
 $factory
 
 $treeStorage
 
 $overrides
 
 $moduleHandler
 

Detailed Description

Manages discovery, instantiation, and tree building of menu link plugins.

This manager finds plugins that are rendered as menu links.

Constructor & Destructor Documentation

__construct ( MenuTreeStorageInterface  $tree_storage,
StaticMenuLinkOverridesInterface  $overrides,
ModuleHandlerInterface  $module_handler 
)

Constructs a object.

Parameters
\Drupal\Core\Menu\MenuTreeStorageInterface$tree_storageThe menu link tree storage.
\Drupal\Core\Menu\StaticMenuLinkOverridesInterface$overridesThe service providing overrides for static links.
\Drupal\Core\Extension\ModuleHandlerInterface$module_handlerThe module handler.

References Drupal\moduleHandler().

Here is the call graph for this function:

Member Function Documentation

addDefinition (   $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$idThe plugin ID for the new menu link definition that is being added.
array$definitionThe values of the link definition.
Returns
A plugin instance created using the newly added definition.
Exceptions
\Drupal\Component\Plugin\Exception\PluginExceptionThrown when the $id is not valid or is an already existing plugin ID.
}

Implements MenuLinkManagerInterface.

References MenuLinkManager\createInstance(), and MenuLinkManager\processDefinition().

Here is the call graph for this function:

countMenuLinks (   $menu_name = NULL)

{Counts the total number of menu links.

Parameters
string$menu_name(optional) The menu name to count by. Defaults to all menus.
Returns
int The number of menu links in the named menu, or in all menus if the menu name is NULL.
}

Implements MenuLinkManagerInterface.

createInstance (   $plugin_id,
array  $configuration = array() 
)

Returns a pre-configured menu link plugin instance.

Parameters
string$plugin_idThe ID of the plugin being instantiated.
array$configurationAn array of configuration relevant to the plugin instance.
Returns
A menu link instance.
Exceptions
\Drupal\Component\Plugin\Exception\PluginExceptionIf the instance cannot be created, such as if the ID is invalid.

Implements FactoryInterface.

References MenuLinkManager\getFactory().

Referenced by MenuLinkManager\addDefinition(), MenuLinkManager\deleteLinksInMenu(), MenuLinkManager\getInstance(), MenuLinkManager\loadLinksByRoute(), MenuLinkManager\removeDefinition(), MenuLinkManager\resetInstance(), MenuLinkManager\resetLink(), and MenuLinkManager\updateDefinition().

Here is the call graph for this function:

Here is the caller graph for this function:

deleteInstance ( MenuLinkInterface  $instance,
  $persist 
)
protected

Deletes a specific instance.

Parameters
\Drupal\Core\Menu\MenuLinkInterface$instanceThe plugin instance to be deleted.
bool$persistIf TRUE, calls MenuLinkInterface::deleteLink() on the instance.
Exceptions
\Drupal\Component\Plugin\Exception\PluginExceptionIf the plugin instance does not support deletion.

References MenuLinkInterface\deleteLink(), PluginInspectionInterface\getPluginId(), and MenuLinkInterface\isDeletable().

Referenced by MenuLinkManager\deleteLinksInMenu(), and MenuLinkManager\removeDefinition().

Here is the call graph for this function:

Here is the caller graph for this function:

deleteLinksInMenu (   $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_nameThe name of the menu whose links will be deleted or reset.
}

Implements MenuLinkManagerInterface.

References MenuLinkManager\createInstance(), MenuLinkManager\deleteInstance(), and MenuLinkManager\resetInstance().

Here is the call graph for this function:

getChildIds (   $id)

{Loads all child link IDs of a given menu link, regardless of visibility.This method is mostly useful for testing.

Parameters
string$idThe menu link plugin ID.
Returns
array An unordered array of IDs representing the IDs of all children, or NULL if the ID is invalid.
}

Implements MenuLinkManagerInterface.

References MenuLinkManager\getDefinition().

Here is the call graph for this function:

getDefinition (   $plugin_id,
  $exception_on_invalid = TRUE 
)

{Gets a specific plugin definition.

Parameters
string$plugin_idA plugin id.
bool$exception_on_invalid(optional) If TRUE, an invalid plugin ID will throw an exception.
Returns
mixed A plugin definition, or NULL if the plugin ID is invalid and $exception_on_invalid is FALSE.
Exceptions
\Drupal\Component\Plugin\Exception\PluginNotFoundExceptionThrown if $plugin_id is invalid and $exception_on_invalid is TRUE.
}

Implements DiscoveryInterface.

Referenced by MenuLinkManager\getChildIds(), MenuLinkManager\getParentIds(), and MenuLinkManager\hasDefinition().

Here is the caller graph for this function:

getDefinitions ( )

{Gets the definition of all plugins for this type.

Returns
mixed[] An array of plugin definitions (empty array if no definitions were found). Keys are plugin IDs.
}

Implements DiscoveryInterface.

References MenuLinkManager\getDiscovery(), Drupal\moduleHandler(), and MenuLinkManager\processDefinition().

Referenced by MenuLinkManager\rebuild(), and MenuLinkManager\resetInstance().

Here is the call graph for this function:

Here is the caller graph for this function:

getDiscovery ( )
protected

Gets the plugin discovery.

Returns

References YamlDiscovery\addTranslatableProperty(), and Drupal\moduleHandler().

Referenced by MenuLinkManager\getDefinitions().

Here is the call graph for this function:

Here is the caller graph for this function:

getFactory ( )
protected

Gets the plugin factory.

Returns

Referenced by MenuLinkManager\createInstance().

Here is the caller graph for this function:

getInstance ( array  $options)

{Gets a preconfigured instance of a plugin.

Parameters
array$optionsAn array of options that can be used to determine a suitable plugin to instantiate and how to configure it.
Returns
object|false A fully configured plugin instance. The interface of the plugin instance will depends on the plugin type. If no instance can be retrieved, FALSE will be returned.
}

Implements MapperInterface.

References MenuLinkManager\createInstance().

Here is the call graph for this function:

getParentIds (   $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$idThe menu link plugin ID.
Returns
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.
}

Implements MenuLinkManagerInterface.

References MenuLinkManager\getDefinition().

Here is the call graph for this function:

hasDefinition (   $plugin_id)

{Indicates if a specific plugin definition exists.

Parameters
string$plugin_idA plugin ID.
Returns
bool TRUE if the definition exists, FALSE otherwise.
}

Implements DiscoveryInterface.

References MenuLinkManager\getDefinition().

Here is the call graph for this function:

loadLinksByRoute (   $route_name,
array  $route_parameters = array(),
  $menu_name = NULL 
)

{Loads multiple plugin instances based on route.

Parameters
string$route_nameThe 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.
Returns
[] An array of instances keyed by plugin ID.
}

Implements MenuLinkManagerInterface.

References MenuLinkManager\createInstance().

Here is the call graph for this function:

menuNameInUse (   $menu_name)

{Determines if any links use a given menu name.

Parameters
string$menu_nameThe menu name.
Returns
bool TRUE if any links are present in the named menu, FALSE otherwise.
}

Implements MenuLinkManagerInterface.

processDefinition ( array &  $definition,
  $plugin_id 
)
protected

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.

Parameters
array$definitionThe definition to be processed and modified by reference.
$plugin_idThe ID of the plugin this definition is being used for.

References NestedArray\mergeDeep().

Referenced by MenuLinkManager\addDefinition(), and MenuLinkManager\getDefinitions().

Here is the call graph for this function:

Here is the caller graph for this function:

rebuild ( )

{Triggers discovery, save, and cleanup of discovered links.}

Implements MenuLinkManagerInterface.

References MenuLinkManager\getDefinitions().

Here is the call graph for this function:

removeDefinition (   $id,
  $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$idThe menu link plugin ID.
bool$persistIf 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
\Drupal\Component\Plugin\Exception\PluginExceptionThrown if the $id is not a valid, existing, plugin ID or if the link cannot be deleted.
}

Implements MenuLinkManagerInterface.

References MenuLinkManager\createInstance(), and MenuLinkManager\deleteInstance().

Here is the call graph for this function:

resetDefinitions ( )

{Resets any local definition cache. Used for testing.}

Implements MenuLinkManagerInterface.

resetInstance ( MenuLinkInterface  $instance)
protected

Resets the menu link to its default settings.

Parameters
\Drupal\Core\Menu\MenuLinkInterface$instanceThe menu link which should be reset.
Returns
The reset menu link.
Exceptions
\Drupal\Component\Plugin\Exception\PluginExceptionThrown when the menu link is not resettable.

References MenuLinkManager\createInstance(), MenuLinkManager\getDefinitions(), PluginInspectionInterface\getPluginId(), and MenuLinkInterface\isResettable().

Referenced by MenuLinkManager\deleteLinksInMenu(), and MenuLinkManager\resetLink().

Here is the call graph for this function:

Here is the caller graph for this function:

resetLink (   $id)

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

Parameters
string$idThe menu link plugin ID.
Returns
The menu link instance after being reset.
Exceptions
\Drupal\Component\Plugin\Exception\PluginExceptionThrown if the $id is not a valid, existing, plugin ID or if the link cannot be reset.
}

Implements MenuLinkManagerInterface.

References MenuLinkManager\createInstance(), and MenuLinkManager\resetInstance().

Here is the call graph for this function:

updateDefinition (   $id,
array  $new_definition_values,
  $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$idThe menu link plugin ID.
array$new_definition_valuesThe new values for the link definition. This will usually be just a subset of the plugin definition.
bool$persistTRUE 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.
Returns
A plugin instance created using the updated definition.
Exceptions
\Drupal\Component\Plugin\Exception\PluginExceptionThrown if the $id is not a valid, existing, plugin ID.
}

Implements MenuLinkManagerInterface.

References MenuLinkManager\createInstance().

Here is the call graph for this function:


The documentation for this class was generated from the following file: