Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / lib / Drupal / Core / Entity / Query / QueryFactory.php
1 <?php
2
3 namespace Drupal\Core\Entity\Query;
4
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);
6
7 use Drupal\Core\Entity\EntityManagerInterface;
8 use Symfony\Component\DependencyInjection\ContainerAwareInterface;
9 use Symfony\Component\DependencyInjection\ContainerAwareTrait;
10
11 /**
12  * Factory class Creating entity query objects.
13  *
14  * Any implementation of this service must call getQuery()/getAggregateQuery()
15  * of the corresponding entity storage.
16  *
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.
20  *
21  * @see https://www.drupal.org/node/2849874
22  * @see \Drupal\Core\Entity\EntityStorageBase::getQuery()
23  */
24 class QueryFactory implements ContainerAwareInterface {
25
26   use ContainerAwareTrait;
27
28   /**
29    * Stores the entity manager used by the query.
30    *
31    * @var \Drupal\Core\Entity\EntityManagerInterface
32    */
33   protected $entityManager;
34
35   /**
36    * Constructs a QueryFactory object.
37    *
38    * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
39    *   The entity manager used by the query.
40    */
41   public function __construct(EntityManagerInterface $entity_manager) {
42     $this->entityManager = $entity_manager;
43   }
44
45   /**
46    * Returns a query object for a given entity type.
47    *
48    * @param string $entity_type_id
49    *   The 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.
53    *
54    * @return \Drupal\Core\Entity\Query\QueryInterface
55    *   The query object that can query the given entity type.
56    */
57   public function get($entity_type_id, $conjunction = 'AND') {
58     return $this->entityManager->getStorage($entity_type_id)->getQuery($conjunction);
59   }
60
61   /**
62    * Returns an aggregated query object for a given entity type.
63    *
64    * @param string $entity_type_id
65    *   The 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.
69    *
70    * @return \Drupal\Core\Entity\Query\QueryAggregateInterface
71    *   The aggregated query object that can query the given entity type.
72    */
73   public function getAggregate($entity_type_id, $conjunction = 'AND') {
74     return $this->entityManager->getStorage($entity_type_id)->getAggregateQuery($conjunction);
75   }
76
77 }