You are here

class MenuLinkConfig in Config menu link 8

Same name in this branch
  1. 8 src/Entity/MenuLinkConfig.php \Drupal\menu_link_config\Entity\MenuLinkConfig
  2. 8 src/Plugin/Derivative/MenuLinkConfig.php \Drupal\menu_link_config\Plugin\Derivative\MenuLinkConfig
  3. 8 src/Plugin/Menu/MenuLinkConfig.php \Drupal\menu_link_config\Plugin\Menu\MenuLinkConfig

Hierarchy

Expanded class hierarchy of MenuLinkConfig

1 string reference to 'MenuLinkConfig'
menu_link_config.links.menu.yml in ./menu_link_config.links.menu.yml
menu_link_config.links.menu.yml

File

src/Plugin/Derivative/MenuLinkConfig.php, line 14
Contains \Drupal\menu_link_config\Plugin\Derivative\MenuLinkConfig.

Namespace

Drupal\menu_link_config\Plugin\Derivative
View source
class MenuLinkConfig implements ContainerDeriverInterface {
  public function __construct(EntityTypeManagerInterface $entity_manager) {
    $this->entityManager = $entity_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($container
      ->get('entity_type.manager'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinition($derivative_id, $base_plugin_definition) {
    if (!isset($this->derivatives)) {
      $this
        ->getDerivativeDefinitions($base_plugin_definition);
    }
    if (isset($this->derivatives[$derivative_id])) {
      return $this->derivatives[$derivative_id];
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $links = [];

    // Get all menu link config entities.
    $entities = $this->entityManager
      ->getStorage('menu_link_config')
      ->loadMultiple(NULL);
    foreach ($entities as $id => $menu_link_config) {

      /** @var \Drupal\menu_link_config\MenuLinkConfigInterface $menu_link_config */
      $links[$id] = $menu_link_config
        ->getPluginDefinition() + $base_plugin_definition;
    }
    return $links;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MenuLinkConfig::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
MenuLinkConfig::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
MenuLinkConfig::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverInterface::getDerivativeDefinitions
MenuLinkConfig::__construct public function