function Context::createFromContext

Same name in other branches
  1. 9 core/lib/Drupal/Core/Plugin/Context/Context.php \Drupal\Core\Plugin\Context\Context::createFromContext()
  2. 10 core/lib/Drupal/Core/Plugin/Context/Context.php \Drupal\Core\Plugin\Context\Context::createFromContext()
  3. 11.x core/lib/Drupal/Core/Plugin/Context/Context.php \Drupal\Core\Plugin\Context\Context::createFromContext()

Overrides ContextInterface::createFromContext

2 calls to Context::createFromContext()
ContextAwarePluginBase::setContextValue in core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php
Sets the value for a defined context.
ContextTest::testSetContextValueCacheableDependency in core/tests/Drupal/Tests/Core/Plugin/Context/ContextTest.php
@covers ::setContextValue

File

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

Class

Context
A Drupal specific context wrapper class.

Namespace

Drupal\Core\Plugin\Context

Code

public static function createFromContext(ContextInterface $old_context, $value) {
    $context = new static($old_context->getContextDefinition(), $value);
    $context->addCacheableDependency($old_context);
    if (method_exists($old_context, 'getTypedDataManager')) {
        $context->setTypedDataManager($old_context->getTypedDataManager());
    }
    return $context;
}

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