comparison core/modules/user/src/Plugin/Action/RemoveRoleUser.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 /**
6 * Removes a role from a user.
7 *
8 * @Action(
9 * id = "user_remove_role_action",
10 * label = @Translation("Remove a role from the selected users"),
11 * type = "user"
12 * )
13 */
14 class RemoveRoleUser extends ChangeUserRoleBase {
15
16 /**
17 * {@inheritdoc}
18 */
19 public function execute($account = NULL) {
20 $rid = $this->configuration['rid'];
21 // Skip removing the role from the user if they already don't have it.
22 if ($account !== FALSE && $account->hasRole($rid)) {
23 // For efficiency manually save the original account before applying
24 // any changes.
25 $account->original = clone $account;
26 $account->removeRole($rid);
27 $account->save();
28 }
29 }
30
31 }