function Context::setContextValue

Same name in other branches
  1. 9 core/lib/Drupal/Core/Plugin/Context/Context.php \Drupal\Core\Plugin\Context\Context::setContextValue()
  2. 8.9.x core/lib/Drupal/Core/Plugin/Context/Context.php \Drupal\Core\Plugin\Context\Context::setContextValue()
  3. 11.x 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);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.