You are here

public static function Context::createFromContext in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Plugin/Context/Context.php \Drupal\Core\Plugin\Context\Context::createFromContext()
  2. 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()
ContextAwarePluginTrait::setContextValue in core/lib/Drupal/Core/Plugin/ContextAwarePluginTrait.php
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;
}