public static function Context::createFromContext in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Plugin/Context/Context.php \Drupal\Core\Plugin\Context\Context::createFromContext()
 
Creates a new context with a different value.
Parameters
\Drupal\Core\Plugin\Context\ContextInterface $old_context: The context object used to create a new object. Cacheability metadata will be copied over.
mixed $value: The value of the new context object.
Return value
static
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\ContextCode
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;
}