Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 20 |
MenuLinkContentDeriver | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 20 |
__construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
create | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 6 |
|||
getDerivativeDefinitions | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 10 |
<?php | |
/** | |
* @file | |
* Contains \Drupal\menu_link_content\Plugin\Deriver\MenuLinkContentDeriver. | |
*/ | |
namespace Drupal\menu_link_content\Plugin\Deriver; | |
use Drupal\Component\Plugin\Derivative\DeriverBase; | |
use Drupal\Core\Entity\EntityManagerInterface; | |
use Drupal\Core\Entity\Query\QueryFactory; | |
use Drupal\Core\Menu\MenuLinkManagerInterface; | |
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
/** | |
* 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. | |
*/ | |
class MenuLinkContentDeriver extends DeriverBase implements ContainerDeriverInterface { | |
/** | |
* The query factory. | |
* | |
* @var \Drupal\Core\Entity\Query\QueryFactory | |
*/ | |
protected $queryFactory; | |
/** | |
* The entity manager. | |
* | |
* @var \Drupal\Core\Entity\EntityManagerInterface | |
*/ | |
protected $entityManager; | |
/** | |
* The menu link manager. | |
* | |
* @var \Drupal\Core\Menu\MenuLinkManagerInterface | |
*/ | |
protected $menuLinkManager; | |
/** | |
* Constructs a MenuLinkContentDeriver instance. | |
* | |
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory | |
* The query factory. | |
* | |
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager | |
* The entity manager. | |
* @param \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager | |
* The menu link manager. | |
*/ | |
public function __construct(QueryFactory $query_factory, EntityManagerInterface $entity_manager, MenuLinkManagerInterface $menu_link_manager) { | |
$this->queryFactory = $query_factory; | |
$this->entityManager = $entity_manager; | |
$this->menuLinkManager = $menu_link_manager; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public static function create(ContainerInterface $container, $base_plugin_id) { | |
return new static( | |
$container->get('entity.query'), | |
$container->get('entity.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->queryFactory->get('menu_link_content') | |
->condition('rediscover', TRUE) | |
->execute(); | |
$plugin_definitions = []; | |
$menu_link_content_entities = $this->entityManager->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; | |
} | |
} |