diff --git a/core/lib/Drupal/Core/Annotation/ContextDefinition.php b/core/lib/Drupal/Core/Annotation/ContextDefinition.php index 38767c5..0b26860 100644 --- a/core/lib/Drupal/Core/Annotation/ContextDefinition.php +++ b/core/lib/Drupal/Core/Annotation/ContextDefinition.php @@ -113,7 +113,7 @@ public function __construct(array $values) { // used in the classes they pass to. foreach (['label', 'description'] as $key) { // @todo Remove this workaround in https://www.drupal.org/node/2362727. - if (isset($values[$key]) && $values[$key] instanceof Translation && $values[$key]->get() instanceof TranslatableString) { + if (isset($values[$key]) && $values[$key] instanceof TranslatableString) { $values[$key] = (string) $values[$key]->get(); } else { diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php index 915d16b..50e4d38 100644 --- a/core/modules/block/src/BlockForm.php +++ b/core/modules/block/src/BlockForm.php @@ -351,8 +351,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $condition_values = (new FormState()) ->setValues($values); $condition->submitConfigurationForm($form, $condition_values); - if ($condition instanceof ContextAwarePluginInterface && $condition->getContextDefinitions()) { - $context_mapping = $condition_values->getValue('context_mapping', []); + if ($condition instanceof ContextAwarePluginInterface) { + $context_mapping = isset($values['context_mapping']) ? $values['context_mapping'] : []; $condition->setContextMapping($context_mapping); } // Update the original form values. diff --git a/core/modules/block/tests/modules/block_test/src/ContextProvider/MultipleStaticContext.php b/core/modules/block/tests/modules/block_test/src/ContextProvider/MultipleStaticContext.php index e316e8b..fea7f6d 100644 --- a/core/modules/block/tests/modules/block_test/src/ContextProvider/MultipleStaticContext.php +++ b/core/modules/block/tests/modules/block_test/src/ContextProvider/MultipleStaticContext.php @@ -15,7 +15,7 @@ use Drupal\Core\Session\AccountInterface; /** - * @todo. + * Sets multiple contexts for a static value. */ class MultipleStaticContext implements ContextProviderInterface { diff --git a/core/tests/Drupal/Tests/Core/Annotation/ContextDefinitionTest.php b/core/tests/Drupal/Tests/Core/Annotation/ContextDefinitionTest.php deleted file mode 100644 index ff313f2..0000000 --- a/core/tests/Drupal/Tests/Core/Annotation/ContextDefinitionTest.php +++ /dev/null @@ -1,69 +0,0 @@ -translationManager = $this->getStringTranslationStub(); - } - - /** - * Test the ContextDefinition Annotation. - */ - public function testContextDefinitionAnnotation() { - $container = new ContainerBuilder(); - $container->set('string_translation', $this->translationManager); - \Drupal::setContainer($container); - - $values = [ - 'value' => 'entity:node', - 'label' => 'test', - 'description' => 'test', - ]; - $context_definition = new ContextDefinition($values); - $definition = $context_definition->get(); - //throw new \Exception(print_r(, TRUE)); - // If the label or description are not a Translation annotation instance, - // it should be replaced by NULL. - $this->assertNull($definition->getLabel()); - $this->assertNull($definition->getDescription()); - - $values = [ - 'value' => 'entity:node', - 'label' => new Translation(['value' => 'test']), - 'description' => new Translation(['value' => 'test']), - ]; - $context_definition = new ContextDefinition($values); - $definition = $context_definition->get(); - //throw new \Exception(print_r(, TRUE)); - // If the label or description are a Translation annotation instance, the - // translated string should be returned. - $this->assertEquals('test', $definition->getLabel()); - $this->assertEquals('test', $definition->getDescription()); - } - -}