Upgraded imagemagick and manually altered pdf to image module to handle changes....
[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\ContentEntityInterface;
8 use Drupal\Core\Entity\EntityTypeInterface;
9 use Drupal\Core\Entity\EntityTypeManagerInterface;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
11
12 /**
13  * Provides a delete action for each content entity type.
14  */
15 class DeleteActionDeriver extends DeriverBase implements ContainerDeriverInterface {
16
17   /**
18    * The entity type manager.
19    *
20    * @var \Drupal\Core\Entity\EntityManagerInterface
21    */
22   protected $entityTypeManager;
23
24   /**
25    * Constructs a new DeleteActionDeriver object.
26    *
27    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
28    *   The entity type manager.
29    */
30   public function __construct(EntityTypeManagerInterface $entity_type_manager) {
31     $this->entityTypeManager = $entity_type_manager;
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   public static function create(ContainerInterface $container, $base_plugin_id) {
38     return new static($container->get('entity_type.manager'));
39   }
40
41   /**
42    * {@inheritdoc}
43    */
44   public function getDerivativeDefinitions($base_plugin_definition) {
45     if (empty($this->derivatives)) {
46       $definitions = [];
47       foreach ($this->getParticipatingEntityTypes() as $entity_type_id => $entity_type) {
48         $definition = $base_plugin_definition;
49         $definition['label'] = t('Delete @entity_type', ['@entity_type' => $entity_type->getSingularLabel()]);
50         $definition['type'] = $entity_type_id;
51         $definition['confirm_form_route_name'] = 'entity.' . $entity_type_id . '.delete_multiple_form';
52         $definitions[$entity_type_id] = $definition;
53       }
54       $this->derivatives = $definitions;
55     }
56
57     return parent::getDerivativeDefinitions($base_plugin_definition);
58   }
59
60   /**
61    * Gets a list of participating entity types.
62    *
63    * The list consists of all content entity types with a delete-multiple-form
64    * link template.
65    *
66    * @return \Drupal\Core\Entity\EntityTypeInterface[]
67    *   The participating entity types, keyed by entity type id.
68    */
69   protected function getParticipatingEntityTypes() {
70     $entity_types = $this->entityTypeManager->getDefinitions();
71     $entity_types = array_filter($entity_types, function (EntityTypeInterface $entity_type) {
72       return $entity_type->entityClassImplements(ContentEntityInterface::class) && $entity_type->hasLinkTemplate('delete-multiple-form');
73     });
74
75     return $entity_types;
76   }
77
78 }