Mercurial > hg > isophonics-drupal-site
comparison core/modules/user/src/Plugin/Action/BlockUser.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\user\Plugin\Action; | |
4 | |
5 use Drupal\Core\Action\ActionBase; | |
6 use Drupal\Core\Session\AccountInterface; | |
7 | |
8 /** | |
9 * Blocks a user. | |
10 * | |
11 * @Action( | |
12 * id = "user_block_user_action", | |
13 * label = @Translation("Block the selected users"), | |
14 * type = "user" | |
15 * ) | |
16 */ | |
17 class BlockUser extends ActionBase { | |
18 | |
19 /** | |
20 * {@inheritdoc} | |
21 */ | |
22 public function execute($account = NULL) { | |
23 // Skip blocking user if they are already blocked. | |
24 if ($account !== FALSE && $account->isActive()) { | |
25 // For efficiency manually save the original account before applying any | |
26 // changes. | |
27 $account->original = clone $account; | |
28 $account->block(); | |
29 $account->save(); | |
30 } | |
31 } | |
32 | |
33 /** | |
34 * {@inheritdoc} | |
35 */ | |
36 public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) { | |
37 /** @var \Drupal\user\UserInterface $object */ | |
38 $access = $object->status->access('edit', $account, TRUE) | |
39 ->andIf($object->access('update', $account, TRUE)); | |
40 | |
41 return $return_as_object ? $access : $access->isAllowed(); | |
42 } | |
43 | |
44 } |