You are here

protected function DomainListBuilder::getEntityIds in Domain Access 8

Loads entity IDs using a pager sorted by the entity weight. The default behavior when using a limit is to sort by id.

We also have to limit by assigned domains of the active user.

See Drupal\Core\Entity\EntityListBuilder::getEntityIds()

Return value

array An array of entity IDs.

Overrides EntityListBuilder::getEntityIds

File

domain/src/DomainListBuilder.php, line 335

Class

DomainListBuilder
User interface for the domain overview screen.

Namespace

Drupal\domain

Code

protected function getEntityIds() {
  $query = $this
    ->getStorage()
    ->getQuery()
    ->sort($this->entityType
    ->getKey('weight'));

  // If the user cannot administer domains, we must filter the query further
  // by assigned IDs. We don't have to check permissions here, because that is
  // handled by the route system and buildRow(). There are two permissions
  // that allow users to view the entire list.
  if (!$this->currentUser
    ->hasPermission('administer domains') && !$this->currentUser
    ->hasPermission('view domain list')) {
    $user = $this->userStorage
      ->load($this->currentUser
      ->id());
    $allowed = $this->domainElementManager
      ->getFieldValues($user, DomainInterface::DOMAIN_ADMIN_FIELD);
    $query
      ->condition('id', array_keys($allowed), 'IN');
  }

  // Only add the pager if a limit is specified.
  if ($this->limit) {
    $query
      ->pager($this->limit);
  }
  return $query
    ->execute();
}