Commit 4c834544 authored by webchick's avatar webchick

Issue #2156835 by chx: ConfigStorageController is not using entity query for loadByProperties.

parent 06d4c62f
......@@ -185,19 +185,6 @@ public function deleteRevision($revision_id) {
return NULL;
}
/**
* Implements Drupal\Core\Entity\EntityStorageControllerInterface::loadByProperties().
*/
public function loadByProperties(array $values = array()) {
$entities = $this->loadMultiple();
foreach ($values as $key => $value) {
$entities = array_filter($entities, function($entity) use ($key, $value) {
return $value === $entity->get($key);
});
}
return $entities;
}
/**
* Returns an entity query instance.
*
......
......@@ -6,6 +6,7 @@
*/
namespace Drupal\Core\Entity;
use Drupal\Core\Entity\Query\QueryInterface;
/**
* A base entity storage controller class.
......@@ -178,4 +179,30 @@ protected function postLoad(array &$queried_entities) {
}
}
/**
* Builds an entity query.
*
* @param \Drupal\Core\Entity\Query\QueryInterface $entity_query
* EntityQuery instance.
* @param array $values
* An associative array of properties of the entity, where the keys are the
* property names and the values are the values those properties must have.
*/
protected function buildPropertyQuery(QueryInterface $entity_query, array $values) {
foreach ($values as $name => $value) {
$entity_query->condition($name, $value);
}
}
/**
* {@inheritdoc}
*/
public function loadByProperties(array $values = array()) {
// Build a query to fetch the entity IDs.
$entity_query = \Drupal::entityQuery($this->entityType);
$this->buildPropertyQuery($entity_query, $values);
$result = $entity_query->execute();
return $result ? $this->loadMultiple($result) : array();
}
}
......@@ -417,24 +417,7 @@ public function deleteRevision($revision_id) {
}
/**
* Implements \Drupal\Core\Entity\EntityStorageControllerInterface::loadByProperties().
*/
public function loadByProperties(array $values = array()) {
// Build a query to fetch the entity IDs.
$entity_query = \Drupal::entityQuery($this->entityType);
$this->buildPropertyQuery($entity_query, $values);
$result = $entity_query->execute();
return $result ? $this->loadMultiple($result) : array();
}
/**
* Builds an entity query.
*
* @param \Drupal\Core\Entity\Query\QueryInterface $entity_query
* EntityQuery instance.
* @param array $values
* An associative array of properties of the entity, where the keys are the
* property names and the values are the values those properties must have.
* {@inheritdoc}
*/
protected function buildPropertyQuery(QueryInterface $entity_query, array $values) {
if ($this->dataTable) {
......@@ -452,9 +435,7 @@ protected function buildPropertyQuery(QueryInterface $entity_query, array $value
}
}
foreach ($values as $name => $value) {
$entity_query->condition($name, $value);
}
parent::buildPropertyQuery($entity_query, $values);
}
/**
......
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