66cf6d0f3637b4db2a3b291a510a65224f2c8028
[yaffs-website] / web / core / modules / user / src / Plugin / Action / RemoveRoleUser.php
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 }