diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index 2dd7ace..e01fe2e 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -134,7 +134,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; } /** diff --git a/core/modules/block/lib/Drupal/block/BlockStorageController.php b/core/modules/block/lib/Drupal/block/BlockStorageController.php index a873c5d..333bb7c 100644 --- a/core/modules/block/lib/Drupal/block/BlockStorageController.php +++ b/core/modules/block/lib/Drupal/block/BlockStorageController.php @@ -40,17 +40,4 @@ public function load(array $ids = NULL) { }); } - /** - * Overrides \Drupal\Core\Config\Entity\ConfigStorageController::loadByProperties(). - */ - 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; - } - } diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityUnitTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityUnitTest.php index 32a198a..a5adf58 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityUnitTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityUnitTest.php @@ -38,6 +38,30 @@ public function testStorageControllerMethods() { $expected = $info['config_prefix'] . '.'; $this->assertIdentical($controller->getConfigPrefix(), $expected); + + // Create three entities, two with the same style. + $style = $this->randomName(); + 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(), + 'style' => $this->randomName(), + )); + $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.'); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php index 1395014..7cc4b96 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php @@ -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.'); } /**