Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. MenuLinkManager.php

function MenuLinkManager::addDefinition

Overrides MenuLinkManagerInterface::addDefinition

File

core/lib/Drupal/Core/Menu/MenuLinkManager.php, line 307

Class

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

Namespace

Drupal\Core\Menu

Code

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);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal