class QueryFactory

Same name in this branch

Factory class Creating entity query objects.

Hierarchy

Expanded class hierarchy of QueryFactory

2 files declare their use of QueryFactory
EfqTest.php in drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/EfqTest.php
Definition of Drupal\taxonomy\Tests\EfqTest.
OpmlFeedAdd.php in drupal/core/modules/aggregator/lib/Drupal/aggregator/Form/OpmlFeedAdd.php
Contains \Drupal\aggregator\Form\OpmlFeedAdd.
1 string reference to 'QueryFactory'
core.services.yml in drupal/core/core.services.yml
drupal/core/core.services.yml
1 service uses QueryFactory

File

drupal/core/lib/Drupal/Core/Entity/Query/QueryFactory.php, line 16
Contains \Drupal\Core\Entity\Query\QueryFactory.

Namespace

Drupal\Core\Entity\Query
View source
class QueryFactory extends ContainerAware {

  /**
   * Stores the entity manager used by the query.
   *
   * @var \Drupal\Core\Entity\EntityManager
   */
  protected $entityManager;

  /**
   * Constructs a QueryFactory object.
   *
   * @param \Drupal\Core\Entity\EntityManager $entity_manager
   *   The entity manager used by the query.
   */
  public function __construct(EntityManager $entity_manager) {
    $this->entityManager = $entity_manager;
  }

  /**
   * Returns a query object for a given entity type.
   *
   * @param string $entity_type
   *   The entity type.
   * @param string $conjunction
   *   - AND: all of the conditions on the query need to match.
   *   - OR: at least one of the conditions on the query need to match.
   *
   * @return \Drupal\Core\Entity\Query\QueryInterface
   *   The query object that can query the given entity type.
   */
  public function get($entity_type, $conjunction = 'AND') {
    $service_name = $this->entityManager
      ->getStorageController($entity_type)
      ->getQueryServicename();
    return $this->container
      ->get($service_name)
      ->get($entity_type, $conjunction, $this->entityManager);
  }

  /**
   * Returns an aggregated query object for a given entity type.
   *
   * @param string $entity_type
   *   The entity type.
   * @param string $conjunction
   *   - AND: all of the conditions on the query need to match.
   *   - OR: at least one of the conditions on the query need to match.
   *
   * @return \Drupal\Core\Entity\Query\QueryAggregateInterface
   *   The aggregated query object that can query the given entity type.
   */
  public function getAggregate($entity_type, $conjunction = 'AND') {
    $service_name = $this->entityManager
      ->getStorageController($entity_type)
      ->getQueryServicename();
    return $this->container
      ->get($service_name)
      ->getAggregate($entity_type, $conjunction, $this->entityManager);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContainerAware::$container protected property @api
ContainerAware::setContainer public function Sets the Container associated with this Controller. Overrides ContainerAwareInterface::setContainer
QueryFactory::$entityManager protected property Stores the entity manager used by the query.
QueryFactory::get public function Returns a query object for a given entity type.
QueryFactory::getAggregate public function Returns an aggregated query object for a given entity type.
QueryFactory::__construct public function Constructs a QueryFactory object.