Skip to content
Snippets Groups Projects
Unverified Commit 7dcb9273 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3014851 by tim.plunkett: ContextAwarePluginBase::setContextValue()...

Issue #3014851 by tim.plunkett: ContextAwarePluginBase::setContextValue() should delegate to ::setContext()
parent 8293016c
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -70,7 +70,7 @@ public function setContext($name, ComponentContextInterface $context) {
* {@inheritdoc}
*/
public function setContextValue($name, $value) {
$this->context[$name] = Context::createFromContext($this->getContext($name), $value);
$this->setContext($name, Context::createFromContext($this->getContext($name), $value));
return $this;
}
......
......@@ -2,11 +2,17 @@
namespace Drupal\Tests\Core\Plugin\Context;
use Drupal\Component\Plugin\Context\ContextInterface as ComponentContextInterface;
use Drupal\Component\Plugin\Definition\ContextAwarePluginDefinitionInterface;
use Drupal\Component\Plugin\Definition\ContextAwarePluginDefinitionTrait;
use Drupal\Component\Plugin\Definition\PluginDefinition;
use Drupal\Component\Plugin\Exception\ContextException;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\Plugin\ContextAwarePluginBase;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\TypedData\Plugin\DataType\StringData;
use Drupal\Core\TypedData\TypedDataManagerInterface;
use Drupal\Tests\UnitTestCase;
/**
......@@ -46,6 +52,22 @@ public function testGetContextDefinition() {
$this->plugin->getContextDefinition('person');
}
/**
* @covers ::setContextValue
*/
public function testSetContextValue() {
$typed_data_manager = $this->prophesize(TypedDataManagerInterface::class);
$container = new ContainerBuilder();
$container->set('typed_data_manager', $typed_data_manager->reveal());
\Drupal::setContainer($container);
$this->plugin->getPluginDefinition()->addContextDefinition('foo', new ContextDefinition('string'));
$this->assertFalse($this->plugin->setContextCalled);
$this->plugin->setContextValue('foo', new StringData(new DataDefinition(), 'bar'));
$this->assertTrue($this->plugin->setContextCalled);
}
}
class TestPluginDefinition extends PluginDefinition implements ContextAwarePluginDefinitionInterface {
......@@ -54,4 +76,21 @@ class TestPluginDefinition extends PluginDefinition implements ContextAwarePlugi
}
class TestContextAwarePlugin extends ContextAwarePluginBase {}
class TestContextAwarePlugin extends ContextAwarePluginBase {
/**
* Indicates if ::setContext() has been called or not.
*
* @var bool
*/
public $setContextCalled = FALSE;
/**
* {@inheritdoc}
*/
public function setContext($name, ComponentContextInterface $context) {
parent::setContext($name, $context);
$this->setContextCalled = TRUE;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment