Mercurial > hg > isophonics-drupal-site
comparison core/modules/user/src/Plugin/Action/AddRoleUser.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 * Adds a role to a user. | |
7 * | |
8 * @Action( | |
9 * id = "user_add_role_action", | |
10 * label = @Translation("Add a role to the selected users"), | |
11 * type = "user" | |
12 * ) | |
13 */ | |
14 class AddRoleUser extends ChangeUserRoleBase { | |
15 | |
16 /** | |
17 * {@inheritdoc} | |
18 */ | |
19 public function execute($account = NULL) { | |
20 $rid = $this->configuration['rid']; | |
21 // Skip adding the role to the user if they already 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->addRole($rid); | |
27 $account->save(); | |
28 } | |
29 } | |
30 | |
31 } |