Security update to Drupal 8.4.6
[yaffs-website] / web / core / modules / config / tests / config_override_integration_test / src / CacheabilityMetadataConfigOverride.php
1 <?php
2
3 namespace Drupal\config_override_integration_test;
4
5 use Drupal\Core\Cache\CacheableMetadata;
6 use Drupal\Core\Config\ConfigFactoryOverrideInterface;
7 use Drupal\Core\Config\StorageInterface;
8
9 /**
10  * Test implementation of a config override that provides cacheability metadata.
11  */
12 class CacheabilityMetadataConfigOverride implements ConfigFactoryOverrideInterface {
13
14   /**
15    * {@inheritdoc}
16    */
17   public function loadOverrides($names) {
18     $overrides = [];
19
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'],
26         ],
27       ];
28     }
29
30     return $overrides;
31   }
32
33   /**
34    * {@inheritdoc}
35    */
36   public function getCacheSuffix() {
37     return 'config_override_integration_test';
38   }
39
40   /**
41    * {@inheritdoc}
42    */
43   public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) {
44     return NULL;
45   }
46
47   /**
48    * {@inheritdoc}
49    */
50   public function getCacheableMetadata($name) {
51     $metadata = new CacheableMetadata();
52     if ($name === 'block.block.config_override_test') {
53       $metadata
54         ->setCacheContexts(['config_override_integration_test'])
55         ->setCacheTags(['config_override_integration_test_tag']);
56     }
57     return $metadata;
58   }
59
60 }