3 namespace Drupal\Core\Action\Plugin\Action;
5 use Drupal\Component\Plugin\DependentPluginInterface;
6 use Drupal\Core\Action\ActionBase;
7 use Drupal\Core\Entity\EntityTypeManagerInterface;
8 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
12 * Base class for entity-based actions.
14 abstract class EntityActionBase extends ActionBase implements DependentPluginInterface, ContainerFactoryPluginInterface {
17 * The entity type manager.
19 * @var \Drupal\Core\Entity\EntityTypeManagerInterface
21 protected $entityTypeManager;
24 * Constructs a EntityActionBase object.
26 * @param mixed[] $configuration
27 * A configuration array containing information about the plugin instance.
28 * @param string $plugin_id
29 * The plugin ID for the plugin instance.
30 * @param mixed $plugin_definition
31 * The plugin implementation definition.
32 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
33 * The entity type manager.
35 public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
36 parent::__construct($configuration, $plugin_id, $plugin_definition);
37 $this->entityTypeManager = $entity_type_manager;
43 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
48 $container->get('entity_type.manager')
55 public function calculateDependencies() {
56 $module_name = $this->entityTypeManager
57 ->getDefinition($this->getPluginDefinition()['type'])
59 return ['module' => [$module_name]];