3 namespace Drupal\Core\Plugin\Context;
5 use Drupal\Component\Plugin\Context\ContextInterface as ComponentContextInterface;
6 use Drupal\Core\Cache\CacheableDependencyInterface;
9 * Context data and definitions for plugins supporting caching and return docs.
11 * @see \Drupal\Component\Plugin\Context\ContextInterface
12 * @see \Drupal\Core\Plugin\Context\ContextDefinitionInterface
14 interface ContextInterface extends ComponentContextInterface, CacheableDependencyInterface {
19 * @return \Drupal\Core\Plugin\Context\ContextDefinitionInterface
21 public function getContextDefinition();
24 * Gets the context value as typed data object.
26 * @return \Drupal\Core\TypedData\TypedDataInterface
28 public function getContextData();
31 * Adds a dependency on an object: merges its cacheability metadata.
33 * For example, when a context depends on some configuration, an entity, or an
34 * access result, we must make sure their cacheability metadata is present on
35 * the response. This method makes doing that simple.
37 * @param \Drupal\Core\Cache\CacheableDependencyInterface|mixed $dependency
38 * The dependency. If the object implements CacheableDependencyInterface,
39 * then its cacheability metadata will be used. Otherwise, the passed in
40 * object must be assumed to be uncacheable, so max-age 0 is set.
44 * @see \Drupal\Core\Cache\CacheableMetadata::createFromObject()
46 public function addCacheableDependency($dependency);
49 * Creates a new context with a different value.
51 * @param \Drupal\Core\Plugin\Context\ContextInterface $old_context
52 * The context object used to create a new object. Cacheability metadata
53 * will be copied over.
55 * The value of the new context object.
59 public static function createFromContext(ContextInterface $old_context, $value);