You are here

class PreviewLinkCacheContext in Preview Link 2.x

Same name and namespace in other branches
  1. 8 src/PreviewLinkCacheContext.php \Drupal\preview_link\PreviewLinkCacheContext
  2. 2.0.x src/PreviewLinkCacheContext.php \Drupal\preview_link\PreviewLinkCacheContext

Defines a class for a preview link cache context.

Hierarchy

Expanded class hierarchy of PreviewLinkCacheContext

1 string reference to 'PreviewLinkCacheContext'
preview_link.services.yml in ./preview_link.services.yml
preview_link.services.yml
1 service uses PreviewLinkCacheContext
cache_context.preview_link_route in ./preview_link.services.yml
Drupal\preview_link\PreviewLinkCacheContext

File

src/PreviewLinkCacheContext.php, line 14

Namespace

Drupal\preview_link
View source
class PreviewLinkCacheContext implements CacheContextInterface {

  /**
   * Route match.
   *
   * @var \Drupal\Core\Routing\RouteMatchInterface
   */
  protected $routeMatch;

  /**
   * Constructs a new PreviewLinkCacheContext.
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch
   *   Route match.
   */
  public function __construct(RouteMatchInterface $routeMatch) {
    $this->routeMatch = $routeMatch;
  }

  /**
   * {@inheritdoc}
   */
  public static function getLabel() {
    return 'Is preview link route';
  }

  /**
   * {@inheritdoc}
   */
  public function getContext() {
    return ($route = $this->routeMatch
      ->getRouteObject()) && $route
      ->getOption('_preview_link_route') ?: FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata() {
    return (new CacheableMetadata())
      ->addCacheTags([
      'routes',
    ]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PreviewLinkCacheContext::$routeMatch protected property Route match.
PreviewLinkCacheContext::getCacheableMetadata public function Gets the cacheability metadata for the context. Overrides CacheContextInterface::getCacheableMetadata
PreviewLinkCacheContext::getContext public function Returns the string representation of the cache context. Overrides CacheContextInterface::getContext
PreviewLinkCacheContext::getLabel public static function Returns the label of the cache context. Overrides CacheContextInterface::getLabel
PreviewLinkCacheContext::__construct public function Constructs a new PreviewLinkCacheContext.