3 namespace Drupal\config_override_integration_test;
5 use Drupal\Core\Cache\CacheableMetadata;
6 use Drupal\Core\Config\ConfigFactoryOverrideInterface;
7 use Drupal\Core\Config\StorageInterface;
10 * Test implementation of a config override that provides cacheability metadata.
12 class CacheabilityMetadataConfigOverride implements ConfigFactoryOverrideInterface {
17 public function loadOverrides($names) {
20 // Override the test block depending on the state set in the test.
21 $state = \Drupal::state()->get('config_override_integration_test.enabled', FALSE);
22 if (in_array('block.block.config_override_test', $names) && $state !== FALSE) {
23 $overrides = $overrides + [
24 'block.block.config_override_test' => [
25 'settings' => ['label' => 'Overridden block label'],
36 public function getCacheSuffix() {
37 return 'config_override_integration_test';
43 public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) {
50 public function getCacheableMetadata($name) {
51 $metadata = new CacheableMetadata();
52 if ($name === 'block.block.config_override_test') {
54 ->setCacheContexts(['config_override_integration_test'])
55 ->setCacheTags(['config_override_integration_test_tag']);