class PreviewLinkCacheContext in Preview Link 8
Same name and namespace in other branches
- 2.x src/PreviewLinkCacheContext.php \Drupal\preview_link\PreviewLinkCacheContext
- 2.0.x src/PreviewLinkCacheContext.php \Drupal\preview_link\PreviewLinkCacheContext
Defines a class for a preview link cache context.
Hierarchy
- class \Drupal\preview_link\PreviewLinkCacheContext implements CacheContextInterface
Expanded class hierarchy of PreviewLinkCacheContext
1 string reference to 'PreviewLinkCacheContext'
1 service uses PreviewLinkCacheContext
File
- src/PreviewLinkCacheContext.php, line 12 
Namespace
Drupal\preview_linkView 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
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| PreviewLinkCacheContext:: | protected | property | Route match. | |
| PreviewLinkCacheContext:: | public | function | Gets the cacheability metadata for the context. Overrides CacheContextInterface:: | |
| PreviewLinkCacheContext:: | public | function | Returns the string representation of the cache context. Overrides CacheContextInterface:: | |
| PreviewLinkCacheContext:: | public static | function | Returns the label of the cache context. Overrides CacheContextInterface:: | |
| PreviewLinkCacheContext:: | public | function | Constructs a new PreviewLinkCacheContext. | 
