comparison core/modules/user/src/Plugin/Action/UnblockUser.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 * Unblocks a user.
10 *
11 * @Action(
12 * id = "user_unblock_user_action",
13 * label = @Translation("Unblock the selected users"),
14 * type = "user"
15 * )
16 */
17 class UnblockUser extends ActionBase {
18
19 /**
20 * {@inheritdoc}
21 */
22 public function execute($account = NULL) {
23 // Skip unblocking user if they are already unblocked.
24 if ($account !== FALSE && $account->isBlocked()) {
25 $account->activate();
26 $account->save();
27 }
28 }
29
30 /**
31 * {@inheritdoc}
32 */
33 public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
34 /** @var \Drupal\user\UserInterface $object */
35 $access = $object->status->access('edit', $account, TRUE)
36 ->andIf($object->access('update', $account, TRUE));
37
38 return $return_as_object ? $access : $access->isAllowed();
39 }
40
41 }