You are here

private function NodeViewCountSettingsForm::getRoleNamesOptions in Node view count 8

Get user role names that are not in excluded user roles.

Data returned in format applicable for '#options' key of form element. Keys are ids of role names, values are labels (human readable names) of roles.

Parameters

array $excluded_user_roles: Excluded user roles.

Return value

array User role names that are not in excluded user roles.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

1 call to NodeViewCountSettingsForm::getRoleNamesOptions()
NodeViewCountSettingsForm::buildForm in src/Form/NodeViewCountSettingsForm.php
Form constructor.

File

src/Form/NodeViewCountSettingsForm.php, line 206

Class

NodeViewCountSettingsForm
Configure nodeviewcount settings.

Namespace

Drupal\nodeviewcount\Form

Code

private function getRoleNamesOptions(array $excluded_user_roles) {
  $roles_options = [];

  /** @var \Drupal\user\RoleInterface[] $roles */
  $roles = $this->entityTypeManager
    ->getStorage('user_role')
    ->loadMultiple();
  foreach ($roles as $role_id => $role) {
    if (!in_array($role_id, $excluded_user_roles)) {
      $roles_options[$role_id] = $role
        ->label();
    }
  }
  return $roles_options;
}