You are here

public function SocialAddRoleUser::execute in Open Social 10.3.x

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

Executes the plugin.

Overrides ExecutableInterface::execute

File

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

Class

SocialAddRoleUser
Adds a role to a user but restricted by role.

Namespace

Drupal\social_user\Plugin\Action

Code

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

  // Skip adding the role to the user if they already have it.
  if ($account !== FALSE && !$account
    ->hasRole($rid)) {

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