You are here

public function SocialRemoveRoleUser::execute in Open Social 8.8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_user/src/Plugin/Action/SocialRemoveRoleUser.php \Drupal\social_user\Plugin\Action\SocialRemoveRoleUser::execute()
  2. 8.7 modules/social_features/social_user/src/Plugin/Action/SocialRemoveRoleUser.php \Drupal\social_user\Plugin\Action\SocialRemoveRoleUser::execute()
  3. 10.3.x modules/social_features/social_user/src/Plugin/Action/SocialRemoveRoleUser.php \Drupal\social_user\Plugin\Action\SocialRemoveRoleUser::execute()
  4. 10.0.x modules/social_features/social_user/src/Plugin/Action/SocialRemoveRoleUser.php \Drupal\social_user\Plugin\Action\SocialRemoveRoleUser::execute()
  5. 10.1.x modules/social_features/social_user/src/Plugin/Action/SocialRemoveRoleUser.php \Drupal\social_user\Plugin\Action\SocialRemoveRoleUser::execute()
  6. 10.2.x modules/social_features/social_user/src/Plugin/Action/SocialRemoveRoleUser.php \Drupal\social_user\Plugin\Action\SocialRemoveRoleUser::execute()

Executes the plugin.

Overrides ExecutableInterface::execute

File

modules/social_features/social_user/src/Plugin/Action/SocialRemoveRoleUser.php, line 63

Class

SocialRemoveRoleUser
Removes a role from a user but restricted by role.

Namespace

Drupal\social_user\Plugin\Action

Code

public function execute($account = NULL) {
  $rid = $this->configuration['rid'];

  // Skip removing the role from the user if they already don't have it.
  if ($account !== FALSE && $account
    ->hasRole($rid)) {

    // For efficiency manually save the original account before applying
    // any changes.
    $account->original = clone $account;
    $account
      ->removeRole($rid);
    $account
      ->save();
  }
}