fcf76a4fbe5f66273b42542ba90f858650802e1a
[yaffs-website] / web / core / lib / Drupal / Core / Action / Plugin / Action / DeleteAction.php
1 <?php
2
3 namespace Drupal\Core\Action\Plugin\Action;
4
5 use Drupal\Core\Entity\EntityTypeManagerInterface;
6 use Drupal\Core\Session\AccountInterface;
7 use Drupal\Core\TempStore\PrivateTempStoreFactory;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
9
10 /**
11  * Redirects to an entity deletion form.
12  *
13  * @Action(
14  *   id = "entity:delete_action",
15  *   action_label = @Translation("Delete"),
16  *   deriver = "Drupal\Core\Action\Plugin\Action\Derivative\EntityDeleteActionDeriver",
17  * )
18  */
19 class DeleteAction extends EntityActionBase {
20
21   /**
22    * The tempstore object.
23    *
24    * @var \Drupal\Core\TempStore\SharedTempStore
25    */
26   protected $tempStore;
27
28   /**
29    * The current user.
30    *
31    * @var \Drupal\Core\Session\AccountInterface
32    */
33   protected $currentUser;
34
35   /**
36    * Constructs a new DeleteAction object.
37    *
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
49    *   Current user.
50    */
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');
54
55     parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager);
56   }
57
58   /**
59    * {@inheritdoc}
60    */
61   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
62     return new static(
63       $configuration,
64       $plugin_id,
65       $plugin_definition,
66       $container->get('entity_type.manager'),
67       $container->get('tempstore.private'),
68       $container->get('current_user')
69     );
70   }
71
72   /**
73    * {@inheritdoc}
74    */
75   public function executeMultiple(array $entities) {
76     /** @var \Drupal\Core\Entity\EntityInterface[] $entities */
77     $selection = [];
78     foreach ($entities as $entity) {
79       $langcode = $entity->language()->getId();
80       $selection[$entity->id()][$langcode] = $langcode;
81     }
82     $this->tempStore->set($this->currentUser->id() . ':' . $this->getPluginDefinition()['type'], $selection);
83   }
84
85   /**
86    * {@inheritdoc}
87    */
88   public function execute($object = NULL) {
89     $this->executeMultiple([$object]);
90   }
91
92   /**
93    * {@inheritdoc}
94    */
95   public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
96     return $object->access('delete', $account, $return_as_object);
97   }
98
99 }