ContextInterface.php 1.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
<?php

/**
 * @file
 * Contains \Drupal\Core\Plugin\Context\ContextInterface.
 */

namespace Drupal\Core\Plugin\Context;

use Drupal\Component\Plugin\Context\ContextInterface as ComponentContextInterface;
11
use Drupal\Core\Cache\CacheableDependencyInterface;
12 13 14 15 16
use Drupal\Core\TypedData\TypedDataInterface;

/**
 * Interface for context.
 */
17
interface ContextInterface extends ComponentContextInterface, CacheableDependencyInterface {
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

  /**
   * Gets the context value as typed data object.
   *
   * @return \Drupal\Core\TypedData\TypedDataInterface
   */
  public function getContextData();

  /**
   * Sets the context value as typed data object.
   *
   * @param \Drupal\Core\TypedData\TypedDataInterface $data
   *   The context value as a typed data object.
   *
   * @return $this
   */
  public function setContextData(TypedDataInterface $data);

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
  /**
   * Adds a dependency on an object: merges its cacheability metadata.
   *
   * E.g. when a context depends on some configuration, an entity, or an access
   * result, we must make sure their cacheability metadata is present on the
   * response. This method makes doing that simple.
   *
   * @param \Drupal\Core\Cache\CacheableDependencyInterface|mixed $dependency
   *   The dependency. If the object implements CacheableDependencyInterface,
   *   then its cacheability metadata will be used. Otherwise, the passed in
   *   object must be assumed to be uncacheable, so max-age 0 is set.
   *
   * @return $this
   *
   * @see \Drupal\Core\Cache\CacheableMetadata::createFromObject()
   */
  public function addCacheableDependency($dependency);

54
}