3 namespace Drupal\Core\Entity\Query;
5 @trigger_error('The ' . __NAMESPACE__ . '\QueryFactory class is deprecated in Drupal 8.3.0, will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityStorageInterface::getQuery() or \Drupal\Core\Entity\EntityStorageInterface::getAggregateQuery() instead. See https://www.drupal.org/node/2849874.', E_USER_DEPRECATED);
7 use Drupal\Core\Entity\EntityManagerInterface;
8 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
9 use Symfony\Component\DependencyInjection\ContainerAwareTrait;
12 * Factory class Creating entity query objects.
14 * Any implementation of this service must call getQuery()/getAggregateQuery()
15 * of the corresponding entity storage.
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 * @see https://www.drupal.org/node/2849874
22 * @see \Drupal\Core\Entity\EntityStorageBase::getQuery()
24 class QueryFactory implements ContainerAwareInterface {
26 use ContainerAwareTrait;
29 * Stores the entity manager used by the query.
31 * @var \Drupal\Core\Entity\EntityManagerInterface
33 protected $entityManager;
36 * Constructs a QueryFactory object.
38 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
39 * The entity manager used by the query.
41 public function __construct(EntityManagerInterface $entity_manager) {
42 $this->entityManager = $entity_manager;
46 * Returns a query object for a given entity type.
48 * @param string $entity_type_id
50 * @param string $conjunction
51 * - AND: all of the conditions on the query need to match.
52 * - OR: at least one of the conditions on the query need to match.
54 * @return \Drupal\Core\Entity\Query\QueryInterface
55 * The query object that can query the given entity type.
57 public function get($entity_type_id, $conjunction = 'AND') {
58 return $this->entityManager->getStorage($entity_type_id)->getQuery($conjunction);
62 * Returns an aggregated query object for a given entity type.
64 * @param string $entity_type_id
66 * @param string $conjunction
67 * - AND: all of the conditions on the query need to match.
68 * - OR: at least one of the conditions on the query need to match.
70 * @return \Drupal\Core\Entity\Query\QueryAggregateInterface
71 * The aggregated query object that can query the given entity type.
73 public function getAggregate($entity_type_id, $conjunction = 'AND') {
74 return $this->entityManager->getStorage($entity_type_id)->getAggregateQuery($conjunction);