diff --git a/core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php b/core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php index 2b97103..457f6ec 100644 --- a/core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php +++ b/core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php @@ -10,6 +10,7 @@ use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Component\Plugin\Context\Context; use Symfony\Component\Validator\ConstraintViolationList; +use Drupal\Component\Plugin\Discovery\DiscoveryInterface; /** * Base class for plugins that are context aware. @@ -24,6 +25,32 @@ protected $context; /** + * Overrides \Drupal\Component\Plugin\PluginBase::__construct(). + * + * Overrides the construction of context aware plugins to allow for + * unvalidated constructor based injection of contexts. + * + * @param array $configuration + * The plugin configuration, i.e. an array with configuration values keyed + * by configuration option name. The special key 'context' may be used to + * initialize the defined contexts by setting it to an array of context + * values keyed by context names. + */ + public function __construct(array $configuration, $plugin_id, DiscoveryInterface $discovery) { + $context = array(); + if (isset($configuration['context'])) { + $context = $configuration['context']; + unset($configuration['context']); + } + parent::__construct($configuration, $plugin_id, $discovery); + foreach ($context as $key => $value) { + $context_definition = $this->getContextDefinition($key); + $this->context[$key] = new Context($context_definition); + $this->context[$key]->setContextValue($value); + } + } + + /** * Implements \Drupal\Component\Plugin\ContextAwarePluginInterface::getContextDefinitions(). */ public function getContextDefinitions() { @@ -109,9 +136,9 @@ public function setContextValue($name, $value) { } /** - * Implements \Drupal\Core\Executable\ExecutableInterface::valdidate(). + * Implements \Drupal\Component\Plugin\ContextAwarePluginInterface::valdidateContexts(). */ - public function validate() { + public function validateContexts() { $violations = new ConstraintViolationList(); // @todo: Implement symfony validator API to let the validator traverse // and set property paths accordingly. diff --git a/core/lib/Drupal/Component/Plugin/ContextAwarePluginInterface.php b/core/lib/Drupal/Component/Plugin/ContextAwarePluginInterface.php index a90f787..2d1aa8a 100644 --- a/core/lib/Drupal/Component/Plugin/ContextAwarePluginInterface.php +++ b/core/lib/Drupal/Component/Plugin/ContextAwarePluginInterface.php @@ -111,6 +111,6 @@ public function setContextValue($name, $value); * A list of constraint violations. If the list is empty, validation * succeeded. */ - public function validate(); + public function validateContexts(); } diff --git a/core/lib/Drupal/Core/Executable/ExecutablePluginBase.php b/core/lib/Drupal/Core/Executable/ExecutablePluginBase.php index b6a4688..426e8b8 100644 --- a/core/lib/Drupal/Core/Executable/ExecutablePluginBase.php +++ b/core/lib/Drupal/Core/Executable/ExecutablePluginBase.php @@ -10,8 +10,6 @@ use Drupal\Core\Plugin\ContextAwarePluginBase; use Symfony\Component\Validator\Validation; use Drupal\Component\Plugin\Exception\PluginException; -use Drupal\Component\Plugin\Discovery\DiscoveryInterface; -use Drupal\Core\Plugin\Context\Context; /** * Provides the basic architecture for executable plugins. @@ -26,32 +24,6 @@ protected $executableManager; /** - * Overrides \Drupal\Component\Plugin\PluginBase::__construct(). - * - * Overrides the construction of executable plugins to allow for unvalidated - * constructor based injection of contexts. - * - * @param array $configuration - * The plugin configuration, i.e. an array with configuration values keyed - * by configuration option name. The special key 'context' may be used to - * initialize the defined contexts by setting it to an array of context - * values keyed by context names. - */ - public function __construct(array $configuration, $plugin_id, DiscoveryInterface $discovery) { - $context = array(); - if (isset($configuration['context'])) { - $context = $configuration['context']; - unset($configuration['context']); - } - parent::__construct($configuration, $plugin_id, $discovery); - foreach ($context as $key => $value) { - $context_definition = $this->getContextDefinition($key); - $this->context[$key] = new Context($context_definition); - $this->context[$key]->setContextValue($value); - } - } - - /** * Implements \Drupal\Core\Executable\ExecutableInterace::setExecutableManager(). */ public function setExecutableManager(ExecutableManagerInterface $executableManager) { diff --git a/core/lib/Drupal/Core/Plugin/Context/Context.php b/core/lib/Drupal/Core/Plugin/Context/Context.php index 3eb195d..e6d680f 100644 --- a/core/lib/Drupal/Core/Plugin/Context/Context.php +++ b/core/lib/Drupal/Core/Plugin/Context/Context.php @@ -70,7 +70,7 @@ public function getTypedContext() { } /** - * Overrides \Drupal\Component\Plugin\Context\Context::getConstraints(). + * Implements \Drupal\Component\Plugin\Context\ContextInterface::getConstraints(). */ public function getConstraints() { if (!empty($this->contextDefinition['type'])) { diff --git a/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php b/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php index a67a3c8..45648d4 100644 --- a/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php +++ b/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php @@ -10,6 +10,7 @@ use Drupal\Component\Plugin\ContextAwarePluginBase as PluginBase; use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Core\Plugin\Context\Context; +use Drupal\Component\Plugin\Discovery\DiscoveryInterface; /** * Drupal specific class for plugins that use context. @@ -21,6 +22,23 @@ abstract class ContextAwarePluginBase extends PluginBase { /** + * Override of \Drupal\Component\Plugin\ContextAwarePluginBase::__construct(). + */ + public function __construct(array $configuration, $plugin_id, DiscoveryInterface $discovery) { + $context = array(); + if (isset($configuration['context'])) { + $context = $configuration['context']; + unset($configuration['context']); + } + parent::__construct($configuration, $plugin_id, $discovery); + foreach ($context as $key => $value) { + $context_definition = $this->getContextDefinition($key); + $this->context[$key] = new Context($context_definition); + $this->context[$key]->setContextValue($value); + } + } + + /** * Override of \Drupal\Component\Plugin\ContextAwarePluginBase::setContextValue(). */ public function setContextValue($name, $value) {