diff --git a/core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php b/core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php index 4cb1aeb689..f50b35a7ea 100644 --- a/core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php +++ b/core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php @@ -298,7 +298,7 @@ public function isSatisfiedBy(ContextInterface $context) { * This should return as many objects as needed to reflect the variations of * the constraints it supports. * - * @return \Drupal\Core\TypedData\TypedDataInterface[] + * @yield \Drupal\Core\TypedData\TypedDataInterface * The set of typed data object. */ protected function getSampleValues() { @@ -314,22 +314,22 @@ protected function getSampleValues() { // If the storage can generate a sample entity we might delegate to that. if ($storage instanceof ContentEntityStorageInterface) { if (!empty($constraints['Bundle']) && $constraints['Bundle'] instanceof BundleConstraint) { - $values = []; foreach ($constraints['Bundle']->bundle as $bundle) { // We have a bundle, we are bundleable and we can generate a sample. - $values[] = EntityAdapter::createFromEntity($storage->createWithSampleValues($bundle)); + yield EntityAdapter::createFromEntity($storage->createWithSampleValues($bundle)); } - return $values; + return; } } // Either no bundle, or not bundleable, so generate an entity adapter. $definition = EntityDataDefinition::create($entity_type_id); - return [new EntityAdapter($definition)]; + yield new EntityAdapter($definition); + return; } // No entity related constraints, so generate a basic typed data object. - return [$this->getTypedDataManager()->create($this->getDataDefinition())]; + yield $this->getTypedDataManager()->create($this->getDataDefinition()); } /** diff --git a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionIsSatisfiedTest.php b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionIsSatisfiedTest.php index dcdaf66edf..f4c9616dee 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionIsSatisfiedTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionIsSatisfiedTest.php @@ -102,7 +102,7 @@ protected function assertRequirementIsSatisfied($expected, ContextDefinition $re /** * @covers ::isSatisfiedBy - * @covers ::getTypedDataObject + * @covers ::getSampleValues * @covers ::getConstraintObjects * * @dataProvider providerTestIsSatisfiedBy @@ -197,7 +197,7 @@ public function providerTestIsSatisfiedBy() { /** * @covers ::isSatisfiedBy - * @covers ::getTypedDataObject + * @covers ::getSampleValues * @covers ::getConstraintObjects * * @dataProvider providerTestIsSatisfiedByGenerateBundledEntity @@ -209,7 +209,9 @@ public function testIsSatisfiedByGenerateBundledEntity($expected, $requirement_c $entity->getEntityTypeId()->willReturn('test_content'); $entity->getIterator()->willReturn(new \ArrayIterator([])); $entity->bundle()->willReturn($bundle); - $content_entity_storage->createWithSampleValues($bundle)->willReturn($entity->reveal()); + $content_entity_storage->createWithSampleValues($bundle) + ->willReturn($entity->reveal()) + ->shouldBeCalled(); } $this->entityTypeManager->getStorage('test_content')->willReturn($content_entity_storage->reveal()); @@ -236,17 +238,17 @@ public function testIsSatisfiedByGenerateBundledEntity($expected, $requirement_c */ public function providerTestIsSatisfiedByGenerateBundledEntity() { $data = []; - $data[] = [TRUE, [], ['first_bundle', 'third_bundle']]; - $data[] = [TRUE, ['first_bundle'], ['first_bundle', 'third_bundle']]; - $data[] = [TRUE, ['first_bundle', 'second_bundle'], ['first_bundle', 'third_bundle']]; - $data[] = [TRUE, ['third_bundle'], 'third_bundle']; + $data[] = [TRUE, [], ['first_bundle']]; + $data[] = [TRUE, ['first_bundle'], ['first_bundle']]; + $data[] = [TRUE, ['first_bundle', 'second_bundle'], ['first_bundle']]; + $data[] = [TRUE, ['third_bundle'], ['first_bundle', 'third_bundle']]; $data[] = [FALSE, ['second_bundle'], ['first_bundle', 'third_bundle']]; return $data; } /** * @covers ::isSatisfiedBy - * @covers ::getTypedDataObject + * @covers ::getSampleValues * @covers ::getConstraintObjects * * @dataProvider providerTestIsSatisfiedByPassBundledEntity