3 namespace Drupal\entity\Plugin\Action\Derivative;
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;
12 * Provides a delete action for each content entity type.
16 class DeleteActionDeriver extends DeriverBase implements ContainerDeriverInterface {
19 * The entity type manager.
21 * @var \Drupal\Core\Entity\EntityManagerInterface
23 protected $entityTypeManager;
26 * Constructs a new DeleteActionDeriver object.
28 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
29 * The entity type manager.
31 public function __construct(EntityTypeManagerInterface $entity_type_manager) {
32 $this->entityTypeManager = $entity_type_manager;
38 public static function create(ContainerInterface $container, $base_plugin_id) {
39 return new static($container->get('entity_type.manager'));
45 public function getDerivativeDefinitions($base_plugin_definition) {
46 if (empty($this->derivatives)) {
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;
55 $this->derivatives = $definitions;
58 return parent::getDerivativeDefinitions($base_plugin_definition);
62 * Gets a list of participating entity types.
64 * The list consists of all content entity types with a delete-multiple-form
67 * @return \Drupal\Core\Entity\EntityTypeInterface[]
68 * The participating entity types, keyed by entity type id.
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');