You are here

public function BackgroundImageSettingsTextCacheContext::getContext in Background Image 8

Same name and namespace in other branches
  1. 2.x src/Cache/Context/BackgroundImageSettingsTextCacheContext.php \Drupal\background_image\Cache\Context\BackgroundImageSettingsTextCacheContext::getContext()
  2. 2.0.x src/Cache/Context/BackgroundImageSettingsTextCacheContext.php \Drupal\background_image\Cache\Context\BackgroundImageSettingsTextCacheContext::getContext()

Returns the string representation of the cache context.

A cache context service's name is used as a token (placeholder) cache key, and is then replaced with the string returned by this method.

Return value

string The string representation of the cache context.

Overrides CacheContextInterface::getContext

File

src/Cache/Context/BackgroundImageSettingsTextCacheContext.php, line 20

Class

BackgroundImageSettingsTextCacheContext
Cache context ID: 'background_image.settings.text'.

Namespace

Drupal\background_image\Cache\Context

Code

public function getContext() {
  $context = $this->backgroundImage ? $this->backgroundImage
    ->getSettingsHash('text') : 0;

  // Add entity specific target if text has tokens.
  if ((!isset($name) || $name === 'text' || $name === 'text.value') && $this->backgroundImage
    ->hasEntityToken() && ($entity = $this->manager
    ->getEntityFromCurrentRoute())) {
    $context .= ":{$entity->getEntityTypeId()}:{$entity->id()}";
  }
  return $context;
}