public function ContextAwarePluginBase::setContextValue

Same name in this branch
  1. 8.x drupal/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php \Drupal\Core\Plugin\ContextAwarePluginBase::setContextValue()
  2. 8.x drupal/core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php \Drupal\Component\Plugin\ContextAwarePluginBase::setContextValue()

Override of \Drupal\Component\Plugin\ContextAwarePluginBase::setContextValue().

Overrides ContextAwarePluginBase::setContextValue

File

drupal/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php, line 44
Contains \Drupal\Core\Plugin\ContextAwarePluginBase

Class

ContextAwarePluginBase
Drupal specific class for plugins that use context.

Namespace

Drupal\Core\Plugin

Code

public function setContextValue($name, $value) {
  $context_definition = $this
    ->getContextDefinition($name);

  // Use the Drupal specific context class.
  $this->context[$name] = new Context($context_definition);
  $this->context[$name]
    ->setContextValue($value);

  // Verify the provided value validates.
  if ($this->context[$name]
    ->validate()
    ->count() > 0) {
    throw new PluginException("The provided context value does not pass validation.");
  }
  return $this;
}