You are here

public function MappingListBuilder::load in GatherContent 8.3

Loads entities of this type from storage for listing.

This allows the implementation to manipulate the listing, like filtering or sorting the loaded entities.

Return value

\Drupal\Core\Entity\EntityInterface[] An array of entities implementing \Drupal\Core\Entity\EntityInterface indexed by their IDs. Returns an empty array if no matching entities are found.

Overrides ConfigEntityListBuilder::load

File

src/MappingListBuilder.php, line 21

Class

MappingListBuilder
Provides a listing of GatherContent Mapping entities.

Namespace

Drupal\gathercontent

Code

public function load() {

  /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface|\Drupal\Core\Entity\Query\QueryInterface $entity_query */
  $entity_query = \Drupal::service('entity.query')
    ->get('gathercontent_mapping');
  $query_string = \Drupal::request()->query;
  $headers = $this
    ->buildHeader();
  $entity_query
    ->pager(100);
  if ($query_string
    ->has('order')) {
    foreach ($headers as $header) {
      if (is_array($header) && $header['data'] === $query_string
        ->get('order')) {
        $sort = 'ASC';
        if ($query_string
          ->has('sort') && $query_string
          ->get('sort') === 'asc' || $query_string
          ->get('sort') === 'desc') {
          $sort = Unicode::strtoupper($query_string
            ->get('sort'));
        }
        $entity_query
          ->sort($header['field'], $sort);
      }
    }
  }
  $entity_query
    ->tableSort($headers);
  $entity_ids = $entity_query
    ->execute();
  return $this->storage
    ->loadMultiple($entity_ids);
}