diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index 5487e04..4443327 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -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; } /** diff --git a/core/modules/block/lib/Drupal/block/BlockStorageController.php b/core/modules/block/lib/Drupal/block/BlockStorageController.php index 80ce276..d6c547d 100644 --- a/core/modules/block/lib/Drupal/block/BlockStorageController.php +++ b/core/modules/block/lib/Drupal/block/BlockStorageController.php @@ -29,19 +29,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} - */ protected function preSave(EntityInterface $entity) { parent::preSave($entity); diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityUnitTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityUnitTest.php index 1e277b8..8be1055 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityUnitTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityUnitTest.php @@ -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.'); } } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php index 9a329f5..909cbcb 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.'); } /**