You are here

protected function WebformEntityListBuilder::getEntityIds in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/WebformEntityListBuilder.php \Drupal\webform\WebformEntityListBuilder::getEntityIds()

Loads entity IDs using a pager sorted by the entity id.

Return value

array An array of entity IDs.

Overrides EntityListBuilder::getEntityIds

1 call to WebformEntityListBuilder::getEntityIds()
WebformEntityListBuilder::load in src/WebformEntityListBuilder.php
Loads entities of this type from storage for listing.

File

src/WebformEntityListBuilder.php, line 452

Class

WebformEntityListBuilder
Defines a class to build a listing of webform entities.

Namespace

Drupal\webform

Code

protected function getEntityIds() {
  $header = $this
    ->buildHeader();
  if ($this->request->query
    ->get('order') === (string) $header['results']['data']) {

    // Get results totals for all returned entity ids.
    $results_totals = $this
      ->getQuery($this->keys, $this->category, $this->state)
      ->execute();
    foreach ($results_totals as $entity_id) {
      $results_totals[$entity_id] = $this->storage
        ->getTotalNumberOfResults($entity_id);
    }

    // Sort results totals.
    asort($results_totals, SORT_NUMERIC);
    if ($this->request->query
      ->get('sort') === 'desc') {
      $results_totals = array_reverse($results_totals, TRUE);
    }

    // Build an associative array of entity ids.
    $entity_ids = array_keys($results_totals);
    $entity_ids = array_combine($entity_ids, $entity_ids);

    // Manually initialize and apply paging to the entity ids.
    $page = $this->request->query
      ->get('page') ?: 0;
    $total = count($entity_ids);
    $limit = $this
      ->getLimit();
    $start = $page * $limit;
    \Drupal::service('pager.manager')
      ->createPager($total, $limit);
    return array_slice($entity_ids, $start, $limit, TRUE);
  }
  else {
    $query = $this
      ->getQuery($this->keys, $this->category, $this->state);
    $query
      ->tableSort($header);
    $query
      ->pager($this
      ->getLimit());
    return $query
      ->execute();
  }
}