ConfigOverrideIntegrationTestCacheContext.php

Same filename in other branches
  1. 9 core/modules/config/tests/config_override_integration_test/src/Cache/ConfigOverrideIntegrationTestCacheContext.php
  2. 10 core/modules/config/tests/config_override_integration_test/src/Cache/ConfigOverrideIntegrationTestCacheContext.php
  3. 11.x core/modules/config/tests/config_override_integration_test/src/Cache/ConfigOverrideIntegrationTestCacheContext.php

Namespace

Drupal\config_override_integration_test\Cache

File

core/modules/config/tests/config_override_integration_test/src/Cache/ConfigOverrideIntegrationTestCacheContext.php

View source
<?php

namespace Drupal\config_override_integration_test\Cache;

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

/**
 * A cache context service intended for the config override integration test.
 *
 * Cache context ID: 'config_override_integration_test'.
 */
class ConfigOverrideIntegrationTestCacheContext implements CacheContextInterface {
    
    /**
     * {@inheritdoc}
     */
    public static function getLabel() {
        return t('Config override integration test');
    }
    
    /**
     * {@inheritdoc}
     */
    public function getContext() {
        // Default to the 'disabled' state.
        $state = \Drupal::state()->get('config_override_integration_test.enabled', FALSE) ? 'yes' : 'no';
        return 'config_override_integration_test.' . $state;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getCacheableMetadata() {
        // Since this depends on State this can change at any time and is not
        // cacheable.
        $metadata = new CacheableMetadata();
        $metadata->setCacheMaxAge(0);
        return $metadata;
    }

}

Classes

Title Deprecated Summary
ConfigOverrideIntegrationTestCacheContext A cache context service intended for the config override integration test.

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