3 namespace Drupal\config_override_test;
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;
11 * Test implementation of a config override that provides cacheability metadata.
13 class PirateDayCacheabilityMetadataConfigOverride implements ConfigFactoryOverrideInterface {
18 public function loadOverrides($names) {
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']];
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!'],
41 public function getCacheSuffix() {
42 return 'PirateDayConfigOverrider';
48 public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) {
55 public function getCacheableMetadata($name) {
56 $metadata = new CacheableMetadata();
58 ->setCacheContexts(['pirate_day'])
59 ->setCacheTags(['pirate-day-tag'])
60 ->setCacheMaxAge(PirateDayCacheContext::PIRATE_DAY_MAX_AGE);