class MenuLinkContentDeriver
Same name in other branches
- 8.9.x core/modules/menu_link_content/src/Plugin/Deriver/MenuLinkContentDeriver.php \Drupal\menu_link_content\Plugin\Deriver\MenuLinkContentDeriver
- 10 core/modules/menu_link_content/src/Plugin/Deriver/MenuLinkContentDeriver.php \Drupal\menu_link_content\Plugin\Deriver\MenuLinkContentDeriver
- 11.x core/modules/menu_link_content/src/Plugin/Deriver/MenuLinkContentDeriver.php \Drupal\menu_link_content\Plugin\Deriver\MenuLinkContentDeriver
Provides a deriver for user entered paths of menu links.
The assumption is that the number of manually entered menu links are lower compared to entity referenced ones.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements \Drupal\Component\Plugin\Derivative\DeriverInterface
- class \Drupal\menu_link_content\Plugin\Deriver\MenuLinkContentDeriver extends \Drupal\Component\Plugin\Derivative\DeriverBase implements \Drupal\Core\Plugin\Discovery\ContainerDeriverInterface
Expanded class hierarchy of MenuLinkContentDeriver
1 string reference to 'MenuLinkContentDeriver'
- menu_link_content.links.menu.yml in core/
modules/ menu_link_content/ menu_link_content.links.menu.yml - core/modules/menu_link_content/menu_link_content.links.menu.yml
File
-
core/
modules/ menu_link_content/ src/ Plugin/ Deriver/ MenuLinkContentDeriver.php, line 17
Namespace
Drupal\menu_link_content\Plugin\DeriverView source
class MenuLinkContentDeriver extends DeriverBase implements ContainerDeriverInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The menu link manager.
*
* @var \Drupal\Core\Menu\MenuLinkManagerInterface
*/
protected $menuLinkManager;
/**
* Constructs a MenuLinkContentDeriver instance.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager
* The menu link manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, MenuLinkManagerInterface $menu_link_manager) {
$this->entityTypeManager = $entity_type_manager;
$this->menuLinkManager = $menu_link_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container->get('entity_type.manager'), $container->get('plugin.manager.menu.link'));
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
// Get all custom menu links which should be rediscovered.
$entity_ids = $this->entityTypeManager
->getStorage('menu_link_content')
->getQuery()
->accessCheck(FALSE)
->condition('rediscover', TRUE)
->execute();
$plugin_definitions = [];
$menu_link_content_entities = $this->entityTypeManager
->getStorage('menu_link_content')
->loadMultiple($entity_ids);
/** @var \Drupal\menu_link_content\MenuLinkContentInterface $menu_link_content */
foreach ($menu_link_content_entities as $menu_link_content) {
$plugin_definitions[$menu_link_content->uuid()] = $menu_link_content->getPluginDefinition();
}
return $plugin_definitions;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
DeriverBase::$derivatives | protected | property | List of derivative definitions. | 1 | |
DeriverBase::getDerivativeDefinition | public | function | Gets the definition of a derivative plugin. | Overrides DeriverInterface::getDerivativeDefinition | |
MenuLinkContentDeriver::$entityTypeManager | protected | property | The entity type manager. | ||
MenuLinkContentDeriver::$menuLinkManager | protected | property | The menu link manager. | ||
MenuLinkContentDeriver::create | public static | function | Creates a new class instance. | Overrides ContainerDeriverInterface::create | |
MenuLinkContentDeriver::getDerivativeDefinitions | public | function | Gets the definition of all derivatives of a base plugin. | Overrides DeriverBase::getDerivativeDefinitions | |
MenuLinkContentDeriver::__construct | public | function | Constructs a MenuLinkContentDeriver instance. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.