You are here

protected function Context::setContextValue in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Plugin/Context/Context.php \Drupal\Core\Plugin\Context\Context::setContextValue()

Sets the context value.

Parameters

mixed $value: The value of this context, matching the context definition.

2 calls to Context::setContextValue()
Context::getContextValue in core/lib/Drupal/Core/Plugin/Context/Context.php
Gets the context value.
Context::__construct in core/lib/Drupal/Core/Plugin/Context/Context.php
Create a context object.

File

core/lib/Drupal/Core/Plugin/Context/Context.php, line 93

Class

Context
A Drupal specific context wrapper class.

Namespace

Drupal\Core\Plugin\Context

Code

protected function setContextValue($value) {

  // Add the value as a cacheable dependency only if implements the interface
  // to prevent it from disabling caching with a max-age 0.
  if ($value instanceof CacheableDependencyInterface) {
    $this
      ->addCacheableDependency($value);
  }
  if ($value instanceof TypedDataInterface) {
    $this->contextData = $value;
  }
  else {
    $this->contextData = $this
      ->getTypedDataManager()
      ->create($this->contextDefinition
      ->getDataDefinition(), $value);
  }
}