MenuLinkConfig.php in Config menu link 8
File
src/Plugin/Derivative/MenuLinkConfig.php
View source
<?php
namespace Drupal\menu_link_config\Plugin\Derivative;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class MenuLinkConfig implements ContainerDeriverInterface {
public function __construct(EntityTypeManagerInterface $entity_manager) {
$this->entityManager = $entity_manager;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('entity_type.manager'));
}
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];
}
}
public function getDerivativeDefinitions($base_plugin_definition) {
$links = [];
$entities = $this->entityManager
->getStorage('menu_link_config')
->loadMultiple(NULL);
foreach ($entities as $id => $menu_link_config) {
$links[$id] = $menu_link_config
->getPluginDefinition() + $base_plugin_definition;
}
return $links;
}
}