Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\user\Plugin\Action;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Action\ActionBase;
|
Chris@0
|
6 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
Chris@0
|
7 use Drupal\Core\Session\AccountInterface;
|
Chris@14
|
8 use Drupal\Core\TempStore\PrivateTempStoreFactory;
|
Chris@0
|
9 use Symfony\Component\DependencyInjection\ContainerInterface;
|
Chris@0
|
10
|
Chris@0
|
11 /**
|
Chris@0
|
12 * Cancels a user account.
|
Chris@0
|
13 *
|
Chris@0
|
14 * @Action(
|
Chris@0
|
15 * id = "user_cancel_user_action",
|
Chris@0
|
16 * label = @Translation("Cancel the selected user accounts"),
|
Chris@0
|
17 * type = "user",
|
Chris@0
|
18 * confirm_form_route_name = "user.multiple_cancel_confirm"
|
Chris@0
|
19 * )
|
Chris@0
|
20 */
|
Chris@0
|
21 class CancelUser extends ActionBase implements ContainerFactoryPluginInterface {
|
Chris@0
|
22
|
Chris@0
|
23 /**
|
Chris@0
|
24 * The tempstore factory.
|
Chris@0
|
25 *
|
Chris@14
|
26 * @var \Drupal\Core\TempStore\PrivateTempStoreFactory
|
Chris@0
|
27 */
|
Chris@0
|
28 protected $tempStoreFactory;
|
Chris@0
|
29
|
Chris@0
|
30 /**
|
Chris@0
|
31 * The current user.
|
Chris@0
|
32 *
|
Chris@0
|
33 * @var \Drupal\Core\Session\AccountInterface
|
Chris@0
|
34 */
|
Chris@0
|
35 protected $currentUser;
|
Chris@0
|
36
|
Chris@0
|
37 /**
|
Chris@17
|
38 * Constructs a CancelUser object.
|
Chris@0
|
39 *
|
Chris@0
|
40 * @param array $configuration
|
Chris@0
|
41 * A configuration array containing information about the plugin instance.
|
Chris@0
|
42 * @param string $plugin_id
|
Chris@0
|
43 * The plugin ID for the plugin instance.
|
Chris@0
|
44 * @param mixed $plugin_definition
|
Chris@0
|
45 * The plugin implementation definition.
|
Chris@14
|
46 * @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
|
Chris@0
|
47 * The tempstore factory.
|
Chris@12
|
48 * @param \Drupal\Core\Session\AccountInterface $current_user
|
Chris@0
|
49 * Current user.
|
Chris@0
|
50 */
|
Chris@0
|
51 public function __construct(array $configuration, $plugin_id, $plugin_definition, PrivateTempStoreFactory $temp_store_factory, AccountInterface $current_user) {
|
Chris@0
|
52 $this->currentUser = $current_user;
|
Chris@0
|
53 $this->tempStoreFactory = $temp_store_factory;
|
Chris@0
|
54
|
Chris@0
|
55 parent::__construct($configuration, $plugin_id, $plugin_definition);
|
Chris@0
|
56 }
|
Chris@0
|
57
|
Chris@0
|
58 /**
|
Chris@0
|
59 * {@inheritdoc}
|
Chris@0
|
60 */
|
Chris@0
|
61 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
Chris@0
|
62 return new static(
|
Chris@0
|
63 $configuration,
|
Chris@0
|
64 $plugin_id,
|
Chris@0
|
65 $plugin_definition,
|
Chris@14
|
66 $container->get('tempstore.private'),
|
Chris@0
|
67 $container->get('current_user')
|
Chris@0
|
68 );
|
Chris@0
|
69 }
|
Chris@0
|
70
|
Chris@0
|
71 /**
|
Chris@0
|
72 * {@inheritdoc}
|
Chris@0
|
73 */
|
Chris@0
|
74 public function executeMultiple(array $entities) {
|
Chris@0
|
75 $this->tempStoreFactory->get('user_user_operations_cancel')->set($this->currentUser->id(), $entities);
|
Chris@0
|
76 }
|
Chris@0
|
77
|
Chris@0
|
78 /**
|
Chris@0
|
79 * {@inheritdoc}
|
Chris@0
|
80 */
|
Chris@0
|
81 public function execute($object = NULL) {
|
Chris@0
|
82 $this->executeMultiple([$object]);
|
Chris@0
|
83 }
|
Chris@0
|
84
|
Chris@0
|
85 /**
|
Chris@0
|
86 * {@inheritdoc}
|
Chris@0
|
87 */
|
Chris@0
|
88 public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
|
Chris@0
|
89 /** @var \Drupal\user\UserInterface $object */
|
Chris@0
|
90 return $object->access('delete', $account, $return_as_object);
|
Chris@0
|
91 }
|
Chris@0
|
92
|
Chris@0
|
93 }
|