5 * Contains \Drupal\linkit\Plugin\Derivative\EntityMatcherDeriver.
8 namespace Drupal\linkit\Plugin\Derivative;
10 use Drupal\Component\Plugin\Derivative\DeriverBase;
11 use Drupal\Component\Utility\Unicode;
12 use Drupal\Core\Entity\EntityManagerInterface;
13 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
14 use Symfony\Component\DependencyInjection\ContainerInterface;
20 class EntityMatcherDeriver extends DeriverBase implements ContainerDeriverInterface {
25 * @var \Drupal\Core\Entity\EntityManagerInterface
27 protected $entityManager;
30 * Creates an EntityMatcherDeriver object.
32 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
35 public function __construct(EntityManagerInterface $entity_manager) {
36 $this->entityManager = $entity_manager;
42 public static function create(ContainerInterface $container, $base_plugin_id) {
44 $container->get('entity.manager')
51 public function getDerivativeDefinitions($base_plugin_definition) {
52 foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
53 $has_canonical = $entity_type->hasLinkTemplate('canonical');
56 $this->derivatives[$entity_type_id] = $base_plugin_definition;
57 $this->derivatives[$entity_type_id]['id'] = $base_plugin_definition['id'] . ':' . $entity_type_id;
58 $this->derivatives[$entity_type_id]['label'] = $entity_type->getLabel();
59 $this->derivatives[$entity_type_id]['target_entity'] = $entity_type_id;
60 $this->derivatives[$entity_type_id]['base_plugin_label'] = (string) $base_plugin_definition['label'];
64 return parent::getDerivativeDefinitions($base_plugin_definition);