You are here

protected function ChannelForm::getAuthorizedUsersOptions in Entity Share 8.3

Same name and namespace in other branches
  1. 8 modules/entity_share_server/src/Form/ChannelForm.php \Drupal\entity_share_server\Form\ChannelForm::getAuthorizedUsersOptions()
  2. 8.2 modules/entity_share_server/src/Form/ChannelForm.php \Drupal\entity_share_server\Form\ChannelForm::getAuthorizedUsersOptions()

Helper function.

Get users with permission entity_share_server_access_channels.

Return value

array An array of options.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

1 call to ChannelForm::getAuthorizedUsersOptions()
ChannelForm::form in modules/entity_share_server/src/Form/ChannelForm.php
Gets the actual form array to be built.

File

modules/entity_share_server/src/Form/ChannelForm.php, line 795

Class

ChannelForm
Entity form for the channel entity.

Namespace

Drupal\entity_share_server\Form

Code

protected function getAuthorizedUsersOptions() {
  $authorized_users = [];
  $authorized_roles = [];
  $users = [];

  // Filter on roles having access to the channel list.

  /** @var \Drupal\user\RoleInterface[] $roles */
  $roles = $this->entityTypeManager
    ->getStorage('user_role')
    ->loadMultiple();
  foreach ($roles as $role) {
    if ($role
      ->hasPermission('entity_share_server_access_channels')) {
      $authorized_roles[] = $role
        ->id();
    }
  }
  if (!empty($authorized_roles)) {
    if (in_array('anonymous', $authorized_roles)) {
      $authorized_users['anonymous'] = $this
        ->t('Anonymous');
    }
    $users = $this->entityTypeManager
      ->getStorage('user')
      ->loadByProperties([
      'roles' => $authorized_roles,
    ]);
  }
  foreach ($users as $user) {
    $authorized_users[$user
      ->uuid()] = $user
      ->label();
  }
  return $authorized_users;
}