Commit 0204ee8e authored by alexpott's avatar alexpott

Issue #2019651 by damiankloip: Add a QueryFactoryInterface for QueryFactory classes.

parent 64a7739a
......@@ -10,13 +10,13 @@
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Entity\Query\QueryAggregateInterface;
use Drupal\Core\Entity\Query\QueryException;
use Drupal\Core\Entity\Query\QueryFactoryInterface;
/**
* Provides a factory for creating entity query objects for the config backend.
*/
class QueryFactory {
class QueryFactory implements QueryFactoryInterface {
/**
* The config storage used by the config entity query.
......@@ -32,41 +32,18 @@ class QueryFactory {
* The config storage used by the config entity query.
*/
public function __construct(StorageInterface $config_storage) {
return $this->configStorage = $config_storage;
$this->configStorage = $config_storage;
}
/**
* Instantiates an entity query for a given entity type.
*
* @param string $entity_type
* The entity type for the query.
* @param string $conjunction
* The operator to use to combine conditions: 'AND' or 'OR'.
* @param \Drupal\Core\Entity\EntityManager $entity_manager
* The entity manager that handles the entity type.
*
* @return \Drupal\Core\Config\Entity\Query\Query
* An entity query for a specific configuration entity type.
* {@inheritdoc}
*/
public function get($entity_type, $conjunction, EntityManager $entity_manager) {
return new Query($entity_type, $conjunction, $entity_manager, $this->configStorage);
}
/**
* Returns a aggregation 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.
*
* @param \Drupal\Core\Entity\EntityManager $entity_manager
* The entity manager.
*
* @throws \Drupal\Core\Entity\Query\QueryException
* @return \Drupal\Core\Entity\Query\QueryAggregateInterface
* The query object that can query the given entity type.
* @inheritdoc
*/
public function getAggregate($entity_type, $conjunction, EntityManager $entity_manager) {
throw new QueryException('Aggregation over configuration entities is not supported');
......
<?php
/**
* @file
* Contains \Drupal\Core\Entity\Query\QueryFactoryInterface.
*/
namespace Drupal\Core\Entity\Query;
use Drupal\Core\Entity\EntityManager;
/**
* Defines an interface for QueryFactory classes.
*/
interface QueryFactoryInterface {
/**
* Instantiates an entity query for a given entity type.
*
* @param string $entity_type
* The entity type for the query.
* @param string $conjunction
* The operator to use to combine conditions: 'AND' or 'OR'.
* @param \Drupal\Core\Entity\EntityManager $entity_manager
* The entity manager that handles the entity type.
* @param \Drupal\Core\Entity\EntityManager $entity_manager
* The entity manager that handles the entity type.
*
* @return \Drupal\Core\Entity\Query\QueryInterface
* An entity query for a specific configuration entity type.
*/
public function get($entity_type, $conjunction, EntityManager $entity_manager);
/**
* Returns a aggregation 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.
* @param \Drupal\Core\Entity\EntityManager $entity_manager
* The entity manager that handles the entity type.
*
* @throws \Drupal\Core\Entity\Query\QueryException
* @return \Drupal\Core\Entity\Query\QueryAggregateInterface
* The query object that can query the given entity type.
*/
public function getAggregate($entity_type, $conjunction, EntityManager $entity_manager);
}
......@@ -9,6 +9,7 @@
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Entity\Query\QueryFactoryInterface;
/**
* Factory class creating entity query objects for the SQL backend.
......@@ -16,7 +17,14 @@
* @see \Drupal\field_sql_storage\Entity\Query
* @see \Drupal\field_sql_storage\Entity\QueryAggregate
*/
class QueryFactory {
class QueryFactory implements QueryFactoryInterface {
/**
* The database connection to use.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* Constructs a QueryFactory object.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment