Mercurial > hg > isophonics-drupal-site
annotate core/modules/user/src/Plugin/Action/RemoveRoleUser.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +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 * Removes a role from a user. |
Chris@0 | 7 * |
Chris@0 | 8 * @Action( |
Chris@0 | 9 * id = "user_remove_role_action", |
Chris@0 | 10 * label = @Translation("Remove a role from the selected users"), |
Chris@0 | 11 * type = "user" |
Chris@0 | 12 * ) |
Chris@0 | 13 */ |
Chris@0 | 14 class RemoveRoleUser 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 removing the role from the user if they already don't 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->removeRole($rid); |
Chris@0 | 27 $account->save(); |
Chris@0 | 28 } |
Chris@0 | 29 } |
Chris@0 | 30 |
Chris@0 | 31 } |