3 namespace Drupal\entity\Plugin\Derivative;
5 use Drupal\Component\Plugin\Derivative\DeriverBase;
6 use Drupal\Core\Entity\EntityTypeManagerInterface;
7 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
11 * Derives local actions for entity types.
13 class EntityActionsDeriver extends DeriverBase implements ContainerDeriverInterface {
16 * The entity type manager.
18 * @var \Drupal\Core\Entity\EntityTypeManagerInterface
20 protected $entityTypeManager;
23 * Constructs an entity local actions deriver.
25 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
26 * The entity type manager.
28 public function __construct(EntityTypeManagerInterface $entity_type_manager) {
29 $this->entityTypeManager = $entity_type_manager;
35 public static function create(ContainerInterface $container, $base_plugin_id) {
36 return new static($container->get('entity_type.manager'));
42 public function getDerivativeDefinitions($base_plugin_definition) {
43 if (!$this->derivatives) {
44 foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
45 $handlers = $entity_type->getHandlerClasses();
46 if (isset($handlers['local_action_provider'])) {
47 foreach ($handlers['local_action_provider'] as $class) {
48 /** @var \Drupal\entity\Menu\EntityLocalActionProviderInterface $handler */
49 $handler = $this->entityTypeManager->createHandlerInstance($class, $entity_type);
50 $this->derivatives += $handler->buildLocalActions($entity_type);
55 return $this->derivatives;