public function AvailableUserRolesService::getAvailableRoles in Multiple Registration 8
Same name and namespace in other branches
- 8.2 src/AvailableUserRolesService.php \Drupal\multiple_registration\AvailableUserRolesService::getAvailableRoles()
- 3.x src/AvailableUserRolesService.php \Drupal\multiple_registration\AvailableUserRolesService::getAvailableRoles()
Get all roles with ability to create registration page.
Return value
array Returns avaliable roles array.
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
1 call to AvailableUserRolesService::getAvailableRoles()
- AvailableUserRolesService::getRegistrationPages in src/
AvailableUserRolesService.php - Get all role ids for whom registration forms was created.
File
- src/
AvailableUserRolesService.php, line 46
Class
- AvailableUserRolesService
- Class AvailableUserRolesService.
Namespace
Drupal\multiple_registrationCode
public function getAvailableRoles() {
$roles = user_role_names();
$role_storage = $this->entityTypeManager
->getStorage('user_role');
$admin_role = $role_storage
->getQuery()
->condition('is_admin', TRUE)
->execute();
$admin_role = reset($admin_role);
$notAvalible = [
AccountInterface::ANONYMOUS_ROLE => $roles[AccountInterface::ANONYMOUS_ROLE],
AccountInterface::AUTHENTICATED_ROLE => $roles[AccountInterface::AUTHENTICATED_ROLE],
$admin_role => $roles[$admin_role],
];
return array_diff_assoc($roles, $notAvalible);
}