You are here

protected function BulkUserRegistration::addRole in Bulk User Registration 8

Add user role.

Parameters

\Drupal\user\UserInterface $user: The user.

string $role: Role Id.

1 call to BulkUserRegistration::addRole()
BulkUserRegistration::createUser in src/BulkUserRegistration.php
Creates and saves a user.

File

src/BulkUserRegistration.php, line 138

Class

BulkUserRegistration
The BulkUserRegistration service.

Namespace

Drupal\bulk_user_registration

Code

protected function addRole(UserInterface $user, $role) {
  if (!in_array($role, [
    RoleInterface::AUTHENTICATED_ID,
    RoleInterface::ANONYMOUS_ID,
  ])) {
    $user
      ->addRole($role);
  }
}