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