Added Entity and Entity Reference Revisions which got dropped somewhere along the...
[yaffs-website] / web / modules / contrib / entity / src / Plugin / Action / Derivative / DeleteActionDeriver.php
1 <?php
2
3 namespace Drupal\entity\Plugin\Action\Derivative;
4
5 use Drupal\Component\Plugin\Derivative\DeriverBase;
6 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
7 use Drupal\Core\Entity\EntityTypeInterface;
8 use Drupal\Core\Entity\EntityTypeManagerInterface;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
10
11 /**
12  * Provides a delete action for each content entity type.
13  *
14  * @deprecated
15  */
16 class DeleteActionDeriver extends DeriverBase implements ContainerDeriverInterface {
17
18   /**
19    * The entity type manager.
20    *
21    * @var \Drupal\Core\Entity\EntityManagerInterface
22    */
23   protected $entityTypeManager;
24
25   /**
26    * Constructs a new DeleteActionDeriver object.
27    *
28    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
29    *   The entity type manager.
30    */
31   public function __construct(EntityTypeManagerInterface $entity_type_manager) {
32     $this->entityTypeManager = $entity_type_manager;
33   }
34
35   /**
36    * {@inheritdoc}
37    */
38   public static function create(ContainerInterface $container, $base_plugin_id) {
39     return new static($container->get('entity_type.manager'));
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public function getDerivativeDefinitions($base_plugin_definition) {
46     if (empty($this->derivatives)) {
47       $definitions = [];
48       foreach ($this->getParticipatingEntityTypes() as $entity_type_id => $entity_type) {
49         $definition = $base_plugin_definition;
50         $definition['label'] = t('Delete @entity_type (Deprecated)', ['@entity_type' => $entity_type->getSingularLabel()]);
51         $definition['type'] = $entity_type_id;
52         $definition['confirm_form_route_name'] = 'entity.' . $entity_type_id . '.delete_multiple_form';
53         $definitions[$entity_type_id] = $definition;
54       }
55       $this->derivatives = $definitions;
56     }
57
58     return parent::getDerivativeDefinitions($base_plugin_definition);
59   }
60
61   /**
62    * Gets a list of participating entity types.
63    *
64    * The list consists of all content entity types with a delete-multiple-form
65    * link template.
66    *
67    * @return \Drupal\Core\Entity\EntityTypeInterface[]
68    *   The participating entity types, keyed by entity type id.
69    */
70   protected function getParticipatingEntityTypes() {
71     $entity_types = $this->entityTypeManager->getDefinitions();
72     $entity_types = array_filter($entity_types, function (EntityTypeInterface $entity_type) {
73       // Core requires a "delete-multiple-confirm" form to be declared as well,
74       // if it's missing, it's safe to assume that the entity type is still
75       // relying on previous Entity API contrib behavior.
76       return $entity_type->hasLinkTemplate('delete-multiple-form') && !$entity_type->hasHandlerClass('form', 'delete-multiple-confirm');
77     });
78
79     return $entity_types;
80   }
81
82 }