Commit 80da26f3 authored by alexpott's avatar alexpott

Issue #1893442 by andypost, tim.plunkett, dawehner: Move...

Issue #1893442 by andypost, tim.plunkett, dawehner: Move BlockStorageController::loadByProperties() into ConfigStorageController.
parent 96b23549
......@@ -169,7 +169,13 @@ public function deleteRevision($revision_id) {
* Implements Drupal\Core\Entity\EntityStorageControllerInterface::loadByProperties().
*/
public function loadByProperties(array $values = array()) {
return array();
$entities = $this->load();
foreach ($values as $key => $value) {
$entities = array_filter($entities, function($entity) use ($key, $value) {
return $value === $entity->get($key);
});
}
return $entities;
}
/**
......
......@@ -26,19 +26,6 @@ public function load(array $ids = NULL) {
});
}
/**
* {@inheritdoc}
*/
public function loadByProperties(array $values = array()) {
$blocks = $this->load();
foreach ($values as $key => $value) {
$blocks = array_filter($blocks, function($block) use ($key, $value) {
return $value === $block->get($key);
});
}
return $blocks;
}
/**
* {@inheritdoc}
*/
......
......@@ -43,6 +43,31 @@ public function testStorageControllerMethods() {
$expected_id = 'test_id';
$config_name = $info['config_prefix'] . '.' . $expected_id;
$this->assertIdentical($controller::getIDFromConfigName($config_name, $info['config_prefix']), $expected_id);
// Create three entities, two with the same style.
$style = $this->randomName(8);
for ($i = 0; $i < 2; $i++) {
$entity = $controller->create(array(
'id' => $this->randomName(),
'label' => $this->randomString(),
'style' => $style,
));
$entity->save();
}
$entity = $controller->create(array(
'id' => $this->randomName(),
'label' => $this->randomString(),
// Use a different length for the entity to ensure uniqueness.
'style' => $this->randomName(9),
));
$entity->save();
$entities = $controller->loadByProperties();
$this->assertEqual(count($entities), 3, 'Three entities are loaded when no properties are specified.');
$entities = $controller->loadByProperties(array('style' => $style));
$this->assertEqual(count($entities), 2, 'Two entities are loaded when the style property is specified.');
$this->assertEqual(reset($entities)->get('style'), $style, 'The loaded entities have the style value specified.');
}
}
......@@ -134,6 +134,19 @@ function testTaxonomyVocabularyLoadMultiple() {
$this->assertEqual(array_shift($vocabularies)->id(), $vocabulary3->id(), 'Vocabulary loaded successfully by ID.');
$this->assertEqual(array_shift($vocabularies)->id(), $vocabulary2->id(), 'Vocabulary loaded successfully by ID.');
$this->assertEqual(array_shift($vocabularies)->id(), $vocabulary1->id(), 'Vocabulary loaded successfully by ID.');
// Test loading vocabularies by their properties.
$controller = $this->container->get('plugin.manager.entity')->getStorageController('taxonomy_vocabulary');
// Fetch vocabulary 1 by name.
$vocabulary = current($controller->loadByProperties(array('name' => $vocabulary1->name)));
$this->assertEqual($vocabulary->id(), $vocabulary1->id(), 'Vocabulary loaded successfully by name.');
// Fetch vocabulary 2 by name and ID.
$vocabulary = current($controller->loadByProperties(array(
'name' => $vocabulary2->name,
'vid' => $vocabulary2->id(),
)));
$this->assertEqual($vocabulary->id(), $vocabulary2->id(), 'Vocabulary loaded successfully by name and ID.');
}
/**
......
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