You are here

abstract class BackgroundImageBaseCacheContext in Background Image 8

Same name and namespace in other branches
  1. 2.x src/Cache/Context/BackgroundImageBaseCacheContext.php \Drupal\background_image\Cache\Context\BackgroundImageBaseCacheContext
  2. 2.0.x src/Cache/Context/BackgroundImageBaseCacheContext.php \Drupal\background_image\Cache\Context\BackgroundImageBaseCacheContext

Provides a base for Background Image based contexts.

Hierarchy

Expanded class hierarchy of BackgroundImageBaseCacheContext

File

src/Cache/Context/BackgroundImageBaseCacheContext.php, line 12

Namespace

Drupal\background_image\Cache\Context
View source
abstract class BackgroundImageBaseCacheContext implements CacheContextInterface {

  /**
   * @var \Drupal\background_image\BackgroundImageManagerInterface
   */
  protected $manager;

  /**
   * @var \Drupal\background_image\BackgroundImageInterface|null
   */
  protected $backgroundImage;

  /**
   * Constructs a BackgroundImageCacheContext object.
   *
   * @param \Drupal\background_image\BackgroundImageManagerInterface $background_image_manager
   */
  public function __construct(BackgroundImageManagerInterface $background_image_manager) {
    $this->manager = $background_image_manager;
    $this->backgroundImage = $background_image_manager
      ->getBackgroundImage();
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata() {
    $metadata = new CacheableMetadata();
    if ($this->backgroundImage) {
      $metadata
        ->addCacheTags($this->backgroundImage
        ->getCacheTags());
    }
    return $metadata;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BackgroundImageBaseCacheContext::$backgroundImage protected property
BackgroundImageBaseCacheContext::$manager protected property
BackgroundImageBaseCacheContext::getCacheableMetadata public function Gets the cacheability metadata for the context. Overrides CacheContextInterface::getCacheableMetadata
BackgroundImageBaseCacheContext::__construct public function Constructs a BackgroundImageCacheContext object.
CacheContextInterface::getContext public function Returns the string representation of the cache context. 23
CacheContextInterface::getLabel public static function Returns the label of the cache context. 23