Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / config / tests / config_override_test / src / PirateDayCacheabilityMetadataConfigOverride.php
1 <?php
2
3 namespace Drupal\config_override_test;
4
5 use Drupal\config_override_test\Cache\PirateDayCacheContext;
6 use Drupal\Core\Cache\CacheableMetadata;
7 use Drupal\Core\Config\ConfigFactoryOverrideInterface;
8 use Drupal\Core\Config\StorageInterface;
9
10 /**
11  * Test implementation of a config override that provides cacheability metadata.
12  */
13 class PirateDayCacheabilityMetadataConfigOverride implements ConfigFactoryOverrideInterface {
14
15   /**
16    * {@inheritdoc}
17    */
18   public function loadOverrides($names) {
19     $overrides = [];
20
21     // Override the theme and the 'call_to_action' block on Pirate Day.
22     if (PirateDayCacheContext::isPirateDay()) {
23       if (in_array('system.theme', $names)) {
24         $overrides = $overrides + ['system.theme' => ['default' => 'pirate']];
25       }
26       if (in_array('block.block.call_to_action', $names)) {
27         $overrides = $overrides + [
28           'block.block.call_to_action' => [
29             'settings' => ['label' => 'Draw yer cutlasses!'],
30           ],
31         ];
32       }
33     }
34
35     return $overrides;
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   public function getCacheSuffix() {
42     return 'PirateDayConfigOverrider';
43   }
44
45   /**
46    * {@inheritdoc}
47    */
48   public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) {
49     return NULL;
50   }
51
52   /**
53    * {@inheritdoc}
54    */
55   public function getCacheableMetadata($name) {
56     $metadata = new CacheableMetadata();
57     $metadata
58       ->setCacheContexts(['pirate_day'])
59       ->setCacheTags(['pirate-day-tag'])
60       ->setCacheMaxAge(PirateDayCacheContext::PIRATE_DAY_MAX_AGE);
61     return $metadata;
62   }
63
64 }