function MenuLinkManager::addDefinition
Same name and namespace in other branches
- 8.9.x core/lib/Drupal/Core/Menu/MenuLinkManager.php \Drupal\Core\Menu\MenuLinkManager::addDefinition()
- 10 core/lib/Drupal/Core/Menu/MenuLinkManager.php \Drupal\Core\Menu\MenuLinkManager::addDefinition()
- 11.x core/lib/Drupal/Core/Menu/MenuLinkManager.php \Drupal\Core\Menu\MenuLinkManager::addDefinition()
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
\Drupal\Core\Menu\MenuLinkInterface A plugin instance created using the newly added definition.
Overrides MenuLinkManagerInterface::addDefinition
File
-
core/
lib/ Drupal/ Core/ Menu/ MenuLinkManager.php, line 346
Class
- MenuLinkManager
- Manages discovery, instantiation, and tree building of menu link plugins.
Namespace
Drupal\Core\MenuCode
public function addDefinition($id, array $definition) {
if ($this->treeStorage
->load($id)) {
throw new PluginException("The menu link ID {$id} already exists as a plugin definition");
}
elseif ($id === '') {
throw new PluginException("The menu link ID cannot be empty");
}
// Add defaults, so there is no requirement to specify everything.
$this->processDefinition($definition, $id);
// Store the new link in the tree.
$this->treeStorage
->save($definition);
return $this->createInstance($id);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.