You are here

class EntityListResponse in Thunder 6.2.x

The thunder entity list response class.

Hierarchy

Expanded class hierarchy of EntityListResponse

3 files declare their use of EntityListResponse
EntitiesWithTerm.php in modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/EntitiesWithTerm.php
ThunderEntityList.php in modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/ThunderEntityList.php
ThunderPagesSchemaExtension.php in modules/thunder_gqls/src/Plugin/GraphQL/SchemaExtension/ThunderPagesSchemaExtension.php

File

modules/thunder_gqls/src/Wrappers/EntityListResponse.php, line 11

Namespace

Drupal\thunder_gqls\Wrappers
View source
class EntityListResponse {

  /**
   * The query interface.
   *
   * @var \Drupal\Core\Entity\Query\QueryInterface
   */
  protected $query;

  /**
   * EntityListResponse constructor.
   *
   * @param \Drupal\Core\Entity\Query\QueryInterface $query
   *   The query interface.
   */
  public function __construct(QueryInterface $query) {
    $this->query = $query;
  }

  /**
   * Calculate the total amount of results.
   *
   * @return int
   *   The total amount of results.
   */
  public function total() {
    $query = clone $this->query;
    $query
      ->range(NULL, NULL)
      ->count();
    return $query
      ->execute();
  }

  /**
   * Retrieve the entity list.
   *
   * @return array|\GraphQL\Deferred
   *   The entity list.
   */
  public function items() {
    $result = $this->query
      ->execute();
    if (empty($result)) {
      return [];
    }
    $buffer = \Drupal::service('graphql.buffer.entity');
    $callback = $buffer
      ->add($this->query
      ->getEntityTypeId(), array_values($result));
    return new Deferred(function () use ($callback) {
      return $callback();
    });
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EntityListResponse::$query protected property The query interface.
EntityListResponse::items public function Retrieve the entity list.
EntityListResponse::total public function Calculate the total amount of results.
EntityListResponse::__construct public function EntityListResponse constructor.