class CacheabilityMetadataConfigOverride

Same name in other branches
  1. 9 core/modules/config/tests/config_override_integration_test/src/CacheabilityMetadataConfigOverride.php \Drupal\config_override_integration_test\CacheabilityMetadataConfigOverride
  2. 10 core/modules/config/tests/config_override_integration_test/src/CacheabilityMetadataConfigOverride.php \Drupal\config_override_integration_test\CacheabilityMetadataConfigOverride
  3. 11.x core/modules/config/tests/config_override_integration_test/src/CacheabilityMetadataConfigOverride.php \Drupal\config_override_integration_test\CacheabilityMetadataConfigOverride

Test implementation of a config override that provides cacheability metadata.

Hierarchy

Expanded class hierarchy of CacheabilityMetadataConfigOverride

1 string reference to 'CacheabilityMetadataConfigOverride'
config_override_integration_test.services.yml in core/modules/config/tests/config_override_integration_test/config_override_integration_test.services.yml
core/modules/config/tests/config_override_integration_test/config_override_integration_test.services.yml
1 service uses CacheabilityMetadataConfigOverride
config_override_integration_test.config_override in core/modules/config/tests/config_override_integration_test/config_override_integration_test.services.yml
Drupal\config_override_integration_test\CacheabilityMetadataConfigOverride

File

core/modules/config/tests/config_override_integration_test/src/CacheabilityMetadataConfigOverride.php, line 12

Namespace

Drupal\config_override_integration_test
View source
class CacheabilityMetadataConfigOverride implements ConfigFactoryOverrideInterface {
    
    /**
     * {@inheritdoc}
     */
    public function loadOverrides($names) {
        $overrides = [];
        // Override the test block depending on the state set in the test.
        $state = \Drupal::state()->get('config_override_integration_test.enabled', FALSE);
        if (in_array('block.block.config_override_test', $names) && $state !== FALSE) {
            $overrides = $overrides + [
                'block.block.config_override_test' => [
                    'settings' => [
                        'label' => 'Overridden block label',
                    ],
                ],
            ];
        }
        return $overrides;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getCacheSuffix() {
        return 'config_override_integration_test';
    }
    
    /**
     * {@inheritdoc}
     */
    public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) {
        return NULL;
    }
    
    /**
     * {@inheritdoc}
     */
    public function getCacheableMetadata($name) {
        $metadata = new CacheableMetadata();
        if ($name === 'block.block.config_override_test') {
            $metadata->setCacheContexts([
                'config_override_integration_test',
            ])
                ->setCacheTags([
                'config_override_integration_test_tag',
            ]);
        }
        return $metadata;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
CacheabilityMetadataConfigOverride::createConfigObject public function Creates a configuration object for use during install and synchronization. Overrides ConfigFactoryOverrideInterface::createConfigObject
CacheabilityMetadataConfigOverride::getCacheableMetadata public function Gets the cacheability metadata associated with the config factory override. Overrides ConfigFactoryOverrideInterface::getCacheableMetadata
CacheabilityMetadataConfigOverride::getCacheSuffix public function The string to append to the configuration static cache name. Overrides ConfigFactoryOverrideInterface::getCacheSuffix
CacheabilityMetadataConfigOverride::loadOverrides public function Returns config overrides. Overrides ConfigFactoryOverrideInterface::loadOverrides

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