Factory class Creating entity query objects.
Expanded class hierarchy of QueryFactory
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);
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
QueryFactory:: |
public | function | Constructs a QueryFactory object. | |
QueryFactory:: |
public | function | Returns a query object for a given entity type. | |
QueryFactory:: |
public | function | Returns an aggregated query object for a given entity type. | |
ContainerAware:: |
public | function |
Sets the Container associated with this Controller. Overrides ContainerAwareInterface:: |
|
QueryFactory:: |
protected | property | Stores the entity manager used by the query. | |
ContainerAware:: |
protected | property | @api |