ContextInterface.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Drupal\Core\Plugin\Context;
  3. use Drupal\Component\Plugin\Context\ContextInterface as ComponentContextInterface;
  4. use Drupal\Core\Cache\CacheableDependencyInterface;
  5. /**
  6. * Context data and definitions for plugins supporting caching and return docs.
  7. *
  8. * @see \Drupal\Component\Plugin\Context\ContextInterface
  9. * @see \Drupal\Core\Plugin\Context\ContextDefinitionInterface
  10. */
  11. interface ContextInterface extends ComponentContextInterface, CacheableDependencyInterface {
  12. /**
  13. * {@inheritdoc}
  14. *
  15. * @return \Drupal\Core\Plugin\Context\ContextDefinitionInterface
  16. */
  17. public function getContextDefinition();
  18. /**
  19. * Gets the context value as typed data object.
  20. *
  21. * @return \Drupal\Core\TypedData\TypedDataInterface
  22. */
  23. public function getContextData();
  24. /**
  25. * Adds a dependency on an object: merges its cacheability metadata.
  26. *
  27. * For example, when a context depends on some configuration, an entity, or an
  28. * access result, we must make sure their cacheability metadata is present on
  29. * the response. This method makes doing that simple.
  30. *
  31. * @param \Drupal\Core\Cache\CacheableDependencyInterface|mixed $dependency
  32. * The dependency. If the object implements CacheableDependencyInterface,
  33. * then its cacheability metadata will be used. Otherwise, the passed in
  34. * object must be assumed to be uncacheable, so max-age 0 is set.
  35. *
  36. * @return $this
  37. *
  38. * @see \Drupal\Core\Cache\CacheableMetadata::createFromObject()
  39. */
  40. public function addCacheableDependency($dependency);
  41. /**
  42. * Creates a new context with a different value.
  43. *
  44. * @param \Drupal\Core\Plugin\Context\ContextInterface $old_context
  45. * The context object used to create a new object. Cacheability metadata
  46. * will be copied over.
  47. * @param mixed $value
  48. * The value of the new context object.
  49. *
  50. * @return static
  51. */
  52. public static function createFromContext(ContextInterface $old_context, $value);
  53. }