Commit fcb52a6a authored by alexpott's avatar alexpott
Browse files

Issue #2191651 by Berdir: Rename...

Issue #2191651 by Berdir: Rename Drupal\Core\Entity\Query\QueryInterface::getEntityType() to getEntityTypeId().
parent 6383d18e
......@@ -10,6 +10,7 @@
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Query\QueryBase;
use Drupal\Core\Entity\Query\QueryInterface;
......@@ -18,13 +19,6 @@
*/
class Query extends QueryBase implements QueryInterface {
/**
* Stores the entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* The config storage used by the config entity query.
*
......@@ -42,13 +36,11 @@ class Query extends QueryBase implements QueryInterface {
/**
* Constructs a Query object.
*
* @param string $entity_type
* The entity type.
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @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\EntityManagerInterface $entity_manager
* The entity manager that stores all meta information.
* @param \Drupal\Core\Config\StorageInterface $config_storage
* The actual config storage which is used to list all config items.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
......@@ -56,9 +48,8 @@ class Query extends QueryBase implements QueryInterface {
* @param array $namespaces
* List of potential namespaces of the classes belonging to this query.
*/
function __construct($entity_type, $conjunction, EntityManagerInterface $entity_manager, StorageInterface $config_storage, ConfigFactoryInterface $config_factory, array $namespaces) {
function __construct(EntityTypeInterface $entity_type, $conjunction, StorageInterface $config_storage, ConfigFactoryInterface $config_factory, array $namespaces) {
parent::__construct($entity_type, $conjunction, $namespaces);
$this->entityManager = $entity_manager;
$this->configStorage = $config_storage;
$this->configFactory = $config_factory;
}
......@@ -126,15 +117,14 @@ public function execute() {
* Config records keyed by entity IDs.
*/
protected function loadRecords() {
$entity_type = $this->entityManager->getDefinition($this->getEntityType());
$prefix = $entity_type->getConfigPrefix() . '.';
$prefix = $this->entityType->getConfigPrefix() . '.';
$prefix_length = strlen($prefix);
// Search the conditions for restrictions on entity IDs.
$ids = array();
if ($this->condition->getConjunction() == 'AND') {
foreach ($this->condition->conditions() as $condition) {
if (is_string($condition['field']) && $condition['field'] == $entity_type->getKey('id')) {
if (is_string($condition['field']) && $condition['field'] == $this->entityType->getKey('id')) {
$operator = $condition['operator'] ?: (is_array($condition['value']) ? 'IN' : '=');
if ($operator == '=') {
$ids = array($condition['value']);
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Query\QueryBase;
use Drupal\Core\Entity\Query\QueryException;
use Drupal\Core\Entity\Query\QueryFactoryInterface;
......@@ -57,14 +58,14 @@ public function __construct(StorageInterface $config_storage, ConfigFactoryInter
/**
* {@inheritdoc}
*/
public function get($entity_type, $conjunction, EntityManagerInterface $entity_manager) {
return new Query($entity_type, $conjunction, $entity_manager, $this->configStorage, $this->configFactory, $this->namespaces);
public function get(EntityTypeInterface $entity_type, $conjunction) {
return new Query($entity_type, $conjunction, $this->configStorage, $this->configFactory, $this->namespaces);
}
/**
* {@inheritdoc}
*/
public function getAggregate($entity_type, $conjunction, EntityManagerInterface $entity_manager) {
public function getAggregate(EntityTypeInterface $entity_type, $conjunction) {
throw new QueryException('Aggregation over configuration entities is not supported');
}
......
......@@ -9,11 +9,12 @@
use Drupal\Core\Database\Query\PagerSelectExtender;
use Drupal\Core\Entity\EntityStorageControllerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
/**
* The base entity query class.
*/
abstract class QueryBase {
abstract class QueryBase implements QueryInterface {
/**
* The entity type this query runs against.
......@@ -22,6 +23,13 @@ abstract class QueryBase {
*/
protected $entityTypeId;
/**
* Information about the entity type.
*
* @var \Drupal\Core\Entity\EntityTypeInterface
*/
protected $entityType;
/**
* The list of sorts.
*
......@@ -127,9 +135,18 @@ abstract class QueryBase {
/**
* Constructs this object.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @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 array $namespaces
* List of potential namespaces of the classes belonging to this query.
*/
public function __construct($entity_type, $conjunction, array $namespaces) {
$this->entityTypeId = $entity_type;
public function __construct(EntityTypeInterface $entity_type, $conjunction, array $namespaces) {
$this->entityTypeId = $entity_type->id();
$this->entityType = $entity_type;
$this->conjunction = $conjunction;
$this->namespaces = $namespaces;
$this->condition = $this->conditionGroupFactory($conjunction);
......@@ -139,9 +156,9 @@ public function __construct($entity_type, $conjunction, array $namespaces) {
}
/**
* Implements \Drupal\Core\Entity\Query\QueryInterface::getEntityType().
* {@inheritdoc}
*/
public function getEntityType() {
public function getEntityTypeId() {
return $this->entityTypeId;
}
......
......@@ -35,8 +35,8 @@ public function __construct(EntityManagerInterface $entity_manager) {
/**
* Returns a query object for a given entity type.
*
* @param string $entity_type
* The entity type.
* @param string $entity_type_id
* The entity type ID.
* @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.
......@@ -44,16 +44,16 @@ public function __construct(EntityManagerInterface $entity_manager) {
* @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);
public function get($entity_type_id, $conjunction = 'AND') {
$service_name = $this->entityManager->getStorageController($entity_type_id)->getQueryServicename();
return $this->container->get($service_name)->get($this->entityManager->getDefinition($entity_type_id), $conjunction);
}
/**
* Returns an aggregated query object for a given entity type.
*
* @param string $entity_type
* The entity type.
* @param string $entity_type_id
* The entity type ID.
* @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.
......@@ -61,9 +61,9 @@ public function get($entity_type, $conjunction = 'AND') {
* @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);
public function getAggregate($entity_type_id, $conjunction = 'AND') {
$service_name = $this->entityManager->getStorageController($entity_type_id)->getQueryServicename();
return $this->container->get($service_name)->getAggregate($this->entityManager->getDefinition($entity_type_id), $conjunction);
}
}
......@@ -6,8 +6,7 @@
*/
namespace Drupal\Core\Entity\Query;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
/**
* Defines an interface for QueryFactory classes.
......@@ -17,35 +16,29 @@ interface QueryFactoryInterface {
/**
* Instantiates an entity query for a given entity type.
*
* @param string $entity_type
* The entity type for the query.
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param string $conjunction
* The operator to use to combine conditions: 'AND' or 'OR'.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager that handles the entity type.
* @param \Drupal\Core\Entity\EntityManagerInterface $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, EntityManagerInterface $entity_manager);
public function get(EntityTypeInterface $entity_type, $conjunction);
/**
* Returns a aggregation query object for a given entity type.
*
* @param string $entity_type
* The entity type.
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @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\EntityManagerInterface $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, EntityManagerInterface $entity_manager);
public function getAggregate(EntityTypeInterface $entity_type, $conjunction);
}
......@@ -19,11 +19,11 @@
interface QueryInterface extends AlterableInterface {
/**
* Gets the entity type for this query.
* Gets the ID of the entity type for this query.
*
* @return string
*/
public function getEntityType();
public function getEntityTypeId();
/**
* Add a condition to the query or a condition group.
......
......@@ -10,6 +10,7 @@
use Drupal\Core\Database\Connection;
use Drupal\Core\Database\Query\SelectInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Query\QueryBase;
use Drupal\Core\Entity\Query\QueryException;
use Drupal\Core\Entity\Query\QueryInterface;
......@@ -19,13 +20,6 @@
*/
class Query extends QueryBase implements QueryInterface {
/**
* The entity type definition.
*
* @var \Drupal\Core\Entity\EntityTypeInterface
*/
protected $entityType;
/**
* The build sql select query.
*
......@@ -68,19 +62,18 @@ class Query extends QueryBase implements QueryInterface {
/**
* Constructs a query object.
*
* @param string $entity_type
* The entity type.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager service.
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @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\Database\Connection $connection
* The database connection to run the query against.
* @param array $namespaces
* List of potential namespaces of the classes belonging to this query.
*/
public function __construct($entity_type, EntityManagerInterface $entity_manager, $conjunction, Connection $connection, array $namespaces) {
public function __construct(EntityTypeInterface $entity_type, $conjunction, Connection $connection, array $namespaces) {
parent::__construct($entity_type, $conjunction, $namespaces);
$this->entityManager = $entity_manager;
$this->connection = $connection;
}
......@@ -107,8 +100,6 @@ public function execute() {
* Returns the called object.
*/
protected function prepare() {
$entity_type = $this->entityTypeId;
$this->entityType = $this->entityManager->getDefinition($entity_type);
if (!$base_table = $this->entityType->getBaseTable()) {
throw new QueryException("No base table, invalid query.");
}
......@@ -117,7 +108,7 @@ protected function prepare() {
$simple_query = FALSE;
}
$this->sqlQuery = $this->connection->select($base_table, 'base_table', array('conjunction' => $this->conjunction));
$this->sqlQuery->addMetaData('entity_type', $entity_type);
$this->sqlQuery->addMetaData('entity_type', $this->entityTypeId);
$id_field = $this->entityType->getKey('id');
// Add the key field for fetchAllKeyed().
if (!$revision_field = $this->entityType->getKey('revision')) {
......@@ -135,7 +126,7 @@ protected function prepare() {
$this->sqlFields["base_table.$id_field"] = array('base_table', $id_field);
}
if ($this->accessCheck) {
$this->sqlQuery->addTag($entity_type . '_access');
$this->sqlQuery->addTag($this->entityTypeId . '_access');
}
$this->sqlQuery->addTag('entity_query');
$this->sqlQuery->addTag('entity_query_' . $this->entityTypeId);
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Query\QueryBase;
use Drupal\Core\Entity\Query\QueryFactoryInterface;
......@@ -46,37 +47,19 @@ public function __construct(Connection $connection) {
}
/**
* Constructs a entity query for a certain 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\Sql\Query
* The factored query.
* {@inheritdoc}
*/
public function get($entity_type, $conjunction, EntityManagerInterface $entity_manager) {
public function get(EntityTypeInterface $entity_type, $conjunction) {
$class = QueryBase::getClass($this->namespaces, 'Query');
return new $class($entity_type, $entity_manager, $conjunction, $this->connection, $this->namespaces);
return new $class($entity_type, $conjunction, $this->connection, $this->namespaces);
}
/**
* Constructs a entity aggregation query for a certain 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\Sql\QueryAggregate
* The factored aggregation query.
* {@inheritdoc}
*/
public function getAggregate($entity_type, $conjunction, EntityManagerInterface $entity_manager) {
public function getAggregate(EntityTypeInterface $entity_type, $conjunction) {
$class = QueryBase::getClass($this->namespaces, 'QueryAggregate');
return new $class($entity_type, $entity_manager, $conjunction, $this->connection, $this->namespaces);
return new $class($entity_type, $conjunction, $this->connection, $this->namespaces);
}
}
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