3 namespace Drupal\Core\Entity\Query;
5 use Drupal\Core\Entity\EntityManagerInterface;
6 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
7 use Symfony\Component\DependencyInjection\ContainerAwareTrait;
10 * Factory class Creating entity query objects.
12 * Any implementation of this service must call getQuery()/getAggregateQuery()
13 * of the corresponding entity storage.
15 * @see \Drupal\Core\Entity\EntityStorageBase::getQuery()
17 * @deprecated in Drupal 8.3.0, will be removed before Drupal 9.0.0. Use
18 * \Drupal\Core\Entity\EntityStorageInterface::getQuery() or
19 * \Drupal\Core\Entity\EntityStorageInterface::getAggregateQuery() instead.
21 class QueryFactory implements ContainerAwareInterface {
23 use ContainerAwareTrait;
26 * Stores the entity manager used by the query.
28 * @var \Drupal\Core\Entity\EntityManagerInterface
30 protected $entityManager;
33 * Constructs a QueryFactory object.
35 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
36 * The entity manager used by the query.
38 public function __construct(EntityManagerInterface $entity_manager) {
39 $this->entityManager = $entity_manager;
43 * Returns a query object for a given entity type.
45 * @param string $entity_type_id
47 * @param string $conjunction
48 * - AND: all of the conditions on the query need to match.
49 * - OR: at least one of the conditions on the query need to match.
51 * @return \Drupal\Core\Entity\Query\QueryInterface
52 * The query object that can query the given entity type.
54 public function get($entity_type_id, $conjunction = 'AND') {
55 return $this->entityManager->getStorage($entity_type_id)->getQuery($conjunction);
59 * Returns an aggregated query object for a given entity type.
61 * @param string $entity_type_id
63 * @param string $conjunction
64 * - AND: all of the conditions on the query need to match.
65 * - OR: at least one of the conditions on the query need to match.
67 * @return \Drupal\Core\Entity\Query\QueryAggregateInterface
68 * The aggregated query object that can query the given entity type.
70 public function getAggregate($entity_type_id, $conjunction = 'AND') {
71 return $this->entityManager->getStorage($entity_type_id)->getAggregateQuery($conjunction);