ViewsTestCacheContext.php

Same filename in other branches
  1. 9 core/modules/views/tests/modules/views_test_data/src/Cache/ViewsTestCacheContext.php
  2. 8.9.x core/modules/views/tests/modules/views_test_data/src/Cache/ViewsTestCacheContext.php
  3. 11.x core/modules/views/tests/modules/views_test_data/src/Cache/ViewsTestCacheContext.php

Namespace

Drupal\views_test_data\Cache

File

core/modules/views/tests/modules/views_test_data/src/Cache/ViewsTestCacheContext.php

View source
<?php

namespace Drupal\views_test_data\Cache;

use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Cache\Context\CacheContextInterface;

/**
 * Test cache context which uses a dynamic context coming from state.
 *
 * Cache context ID: 'views_test_cache_context'.
 */
class ViewsTestCacheContext implements CacheContextInterface {
    
    /**
     * {@inheritdoc}
     */
    public static function getLabel() {
        return t('Views test cache context');
    }
    
    /**
     * {@inheritdoc}
     */
    public function getContext() {
        return \Drupal::state()->get('views_test_cache_context', 'George');
    }
    
    /**
     * {@inheritdoc}
     */
    public function getCacheableMetadata() {
        return new CacheableMetadata();
    }

}

Classes

Title Deprecated Summary
ViewsTestCacheContext Test cache context which uses a dynamic context coming from state.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.