Mercurial > hg > isophonics-drupal-site
annotate core/modules/user/src/Plugin/Action/AddRoleUser.php @ 15:e200cb7efeb3
Update Drupal core to 8.5.3 via Composer
| author | Chris Cannam |
|---|---|
| date | Thu, 26 Apr 2018 11:26:54 +0100 |
| parents | 4c8ae668cc8c |
| children |
| rev | line source |
|---|---|
| Chris@0 | 1 <?php |
| Chris@0 | 2 |
| Chris@0 | 3 namespace Drupal\user\Plugin\Action; |
| Chris@0 | 4 |
| Chris@0 | 5 /** |
| Chris@0 | 6 * Adds a role to a user. |
| Chris@0 | 7 * |
| Chris@0 | 8 * @Action( |
| Chris@0 | 9 * id = "user_add_role_action", |
| Chris@0 | 10 * label = @Translation("Add a role to the selected users"), |
| Chris@0 | 11 * type = "user" |
| Chris@0 | 12 * ) |
| Chris@0 | 13 */ |
| Chris@0 | 14 class AddRoleUser extends ChangeUserRoleBase { |
| Chris@0 | 15 |
| Chris@0 | 16 /** |
| Chris@0 | 17 * {@inheritdoc} |
| Chris@0 | 18 */ |
| Chris@0 | 19 public function execute($account = NULL) { |
| Chris@0 | 20 $rid = $this->configuration['rid']; |
| Chris@0 | 21 // Skip adding the role to the user if they already have it. |
| Chris@0 | 22 if ($account !== FALSE && !$account->hasRole($rid)) { |
| Chris@0 | 23 // For efficiency manually save the original account before applying |
| Chris@0 | 24 // any changes. |
| Chris@0 | 25 $account->original = clone $account; |
| Chris@0 | 26 $account->addRole($rid); |
| Chris@0 | 27 $account->save(); |
| Chris@0 | 28 } |
| Chris@0 | 29 } |
| Chris@0 | 30 |
| Chris@0 | 31 } |
