3 namespace Drupal\Core\Action\Plugin\Action;
5 use Drupal\Core\Entity\EntityTypeManagerInterface;
6 use Drupal\Core\Session\AccountInterface;
7 use Drupal\Core\TempStore\PrivateTempStoreFactory;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
11 * Redirects to an entity deletion form.
14 * id = "entity:delete_action",
15 * action_label = @Translation("Delete"),
16 * deriver = "Drupal\Core\Action\Plugin\Action\Derivative\EntityDeleteActionDeriver",
19 class DeleteAction extends EntityActionBase {
22 * The tempstore object.
24 * @var \Drupal\Core\TempStore\SharedTempStore
31 * @var \Drupal\Core\Session\AccountInterface
33 protected $currentUser;
36 * Constructs a new DeleteAction object.
38 * @param array $configuration
39 * A configuration array containing information about the plugin instance.
40 * @param string $plugin_id
41 * The plugin ID for the plugin instance.
42 * @param mixed $plugin_definition
43 * The plugin implementation definition.
44 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
45 * The entity type manager.
46 * @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
47 * The tempstore factory.
48 * @param \Drupal\Core\Session\AccountInterface $current_user
51 public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, PrivateTempStoreFactory $temp_store_factory, AccountInterface $current_user) {
52 $this->currentUser = $current_user;
53 $this->tempStore = $temp_store_factory->get('entity_delete_multiple_confirm');
55 parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager);
61 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
66 $container->get('entity_type.manager'),
67 $container->get('tempstore.private'),
68 $container->get('current_user')
75 public function executeMultiple(array $entities) {
76 /** @var \Drupal\Core\Entity\EntityInterface[] $entities */
78 foreach ($entities as $entity) {
79 $langcode = $entity->language()->getId();
80 $selection[$entity->id()][$langcode] = $langcode;
82 $this->tempStore->set($this->currentUser->id() . ':' . $this->getPluginDefinition()['type'], $selection);
88 public function execute($object = NULL) {
89 $this->executeMultiple([$object]);
95 public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
96 return $object->access('delete', $account, $return_as_object);