e9726b436d7a686229c3420c724b02ef2d3d9b30
[yaffs-website] / web / core / modules / user / src / Plugin / Action / CancelUser.php
1 <?php
2
3 namespace Drupal\user\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  * Cancels a user account.
13  *
14  * @Action(
15  *   id = "user_cancel_user_action",
16  *   label = @Translation("Cancel the selected user accounts"),
17  *   type = "user",
18  *   confirm_form_route_name = "user.multiple_cancel_confirm"
19  * )
20  */
21 class CancelUser extends ActionBase implements ContainerFactoryPluginInterface {
22
23   /**
24    * The tempstore factory.
25    *
26    * @var \Drupal\Core\TempStore\PrivateTempStoreFactory
27    */
28   protected $tempStoreFactory;
29
30   /**
31    * The current user.
32    *
33    * @var \Drupal\Core\Session\AccountInterface
34    */
35   protected $currentUser;
36
37   /**
38    * Constructs a DeleteNode object.
39    *
40    * @param array $configuration
41    *   A configuration array containing information about the plugin instance.
42    * @param string $plugin_id
43    *   The plugin ID for the plugin instance.
44    * @param mixed $plugin_definition
45    *   The plugin implementation definition.
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, PrivateTempStoreFactory $temp_store_factory, AccountInterface $current_user) {
52     $this->currentUser = $current_user;
53     $this->tempStoreFactory = $temp_store_factory;
54
55     parent::__construct($configuration, $plugin_id, $plugin_definition);
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('tempstore.private'),
67       $container->get('current_user')
68     );
69   }
70
71   /**
72    * {@inheritdoc}
73    */
74   public function executeMultiple(array $entities) {
75     $this->tempStoreFactory->get('user_user_operations_cancel')->set($this->currentUser->id(), $entities);
76   }
77
78   /**
79    * {@inheritdoc}
80    */
81   public function execute($object = NULL) {
82     $this->executeMultiple([$object]);
83   }
84
85   /**
86    * {@inheritdoc}
87    */
88   public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
89     /** @var \Drupal\user\UserInterface $object */
90     return $object->access('delete', $account, $return_as_object);
91   }
92
93 }