public function SocialAddRoleUser::execute in Open Social 8.8
Same name and namespace in other branches
- 8.9 modules/social_features/social_user/src/Plugin/Action/SocialAddRoleUser.php \Drupal\social_user\Plugin\Action\SocialAddRoleUser::execute()
- 8.7 modules/social_features/social_user/src/Plugin/Action/SocialAddRoleUser.php \Drupal\social_user\Plugin\Action\SocialAddRoleUser::execute()
- 10.3.x modules/social_features/social_user/src/Plugin/Action/SocialAddRoleUser.php \Drupal\social_user\Plugin\Action\SocialAddRoleUser::execute()
- 10.0.x modules/social_features/social_user/src/Plugin/Action/SocialAddRoleUser.php \Drupal\social_user\Plugin\Action\SocialAddRoleUser::execute()
- 10.1.x modules/social_features/social_user/src/Plugin/Action/SocialAddRoleUser.php \Drupal\social_user\Plugin\Action\SocialAddRoleUser::execute()
- 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\ActionCode
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();
}
}