You are here

public function Webform::getCacheContexts in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Entity/Webform.php \Drupal\webform\Entity\Webform::getCacheContexts()

The cache contexts associated with this object.

These identify a specific variation/representation of the object.

Cache contexts are tokens: placeholders that are converted to cache keys by the @cache_contexts_manager service. The replacement value depends on the request context (the current URL, language, and so on). They're converted before storing an object in cache.

Return value

string[] An array of cache context tokens, used to generate a cache ID.

Overrides EntityBase::getCacheContexts

See also

\Drupal\Core\Cache\Context\CacheContextsManager::convertTokensToKeys()

File

src/Entity/Webform.php, line 2249

Class

Webform
Defines the webform entity.

Namespace

Drupal\webform\Entity

Code

public function getCacheContexts() {
  $cache_contexts = parent::getCacheContexts();

  // Add all prepopulate query string parameters.
  if ($this
    ->getSetting('form_prepopulate')) {
    $cache_contexts[] = 'url.query_args';
  }
  else {

    // Add source entity type and id query string parameters.
    if ($this
      ->getSetting('form_prepopulate_source_entity')) {
      $cache_contexts[] = 'url.query_args:source_entity_type';
      $cache_contexts[] = 'url.query_args:source_entity_id';
    }

    // Add webform (secure) token query string parameter.
    if ($this
      ->getSetting('token_view') || $this
      ->getSetting('token_update') || $this
      ->getSetting('token_delete')) {
      $cache_contexts[] = 'url.query_args:token';
    }
  }
  return $cache_contexts;
}