3 namespace Drupal\entity\Plugin\Action;
5 use Drupal\Core\Action\ActionBase;
6 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
7 use Drupal\Core\Session\AccountInterface;
8 use Drupal\Core\TempStore\PrivateTempStoreFactory;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
12 * Redirects to an entity deletion form.
15 * id = "entity_delete_action",
16 * label = @Translation("Delete entity"),
17 * deriver = "Drupal\entity\Plugin\Action\Derivative\DeleteActionDeriver",
20 class DeleteAction extends ActionBase implements ContainerFactoryPluginInterface {
23 * The tempstore object.
25 * @var \Drupal\Core\TempStore\SharedTempStore
32 * @var \Drupal\Core\Session\AccountInterface
34 protected $currentUser;
37 * Constructs a new DeleteAction object.
39 * @param array $configuration
40 * A configuration array containing information about the plugin instance.
41 * @param string $plugin_id
42 * The plugin ID for the plugin instance.
43 * @param mixed $plugin_definition
44 * The plugin implementation definition.
45 * @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
46 * The tempstore factory.
47 * @param AccountInterface $current_user
50 public function __construct(array $configuration, $plugin_id, $plugin_definition, PrivateTempStoreFactory $temp_store_factory, AccountInterface $current_user) {
51 $this->currentUser = $current_user;
52 $this->tempStore = $temp_store_factory->get('entity_delete_multiple_confirm');
54 parent::__construct($configuration, $plugin_id, $plugin_definition);
60 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
65 $container->get('tempstore.private'),
66 $container->get('current_user')
73 public function executeMultiple(array $entities) {
74 /** @var \Drupal\Core\Entity\EntityInterface[] $entities */
76 foreach ($entities as $entity) {
77 $langcode = $entity->language()->getId();
78 $selection[$entity->id()][$langcode] = $langcode;
80 $this->tempStore->set($this->currentUser->id() . ':' . $this->getPluginDefinition()['type'], $selection);
86 public function execute($object = NULL) {
87 $this->executeMultiple([$object]);
93 public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
94 return $object->access('delete', $account, $return_as_object);