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()

Implements \Drupal\Component\Plugin\ContextAwarePluginInterface::setContextValue().

Overrides ContextAwarePluginInterface::setContextValue

1 method overrides ContextAwarePluginBase::setContextValue()

File

drupal/core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php, line 125
Contains \Drupal\Component\Plugin\ContextAwarePluginBase

Class

ContextAwarePluginBase
Base class for plugins that are context aware.

Namespace

Drupal\Component\Plugin

Code

public function setContextValue($name, $value) {
  $context_definition = $this
    ->getContextDefinition($name);
  $this->context[$name] = new Context($context_definition);
  $this->context[$name]
    ->setContextValue($value);

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