Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / lib / Drupal / Core / Action / Plugin / Action / EntityActionBase.php
1 <?php
2
3 namespace Drupal\Core\Action\Plugin\Action;
4
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;
10
11 /**
12  * Base class for entity-based actions.
13  */
14 abstract class EntityActionBase extends ActionBase implements DependentPluginInterface, ContainerFactoryPluginInterface {
15
16   /**
17    * The entity type manager.
18    *
19    * @var \Drupal\Core\Entity\EntityTypeManagerInterface
20    */
21   protected $entityTypeManager;
22
23   /**
24    * Constructs a EntityActionBase object.
25    *
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.
34    */
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;
38   }
39
40   /**
41    * {@inheritdoc}
42    */
43   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
44     return new static(
45       $configuration,
46       $plugin_id,
47       $plugin_definition,
48       $container->get('entity_type.manager')
49     );
50   }
51
52   /**
53    * {@inheritdoc}
54    */
55   public function calculateDependencies() {
56     $module_name = $this->entityTypeManager
57       ->getDefinition($this->getPluginDefinition()['type'])
58       ->getProvider();
59     return ['module' => [$module_name]];
60   }
61
62 }