PirateDayCacheabilityMetadataConfigOverride.php in Drupal 10
File
core/modules/config/tests/config_override_test/src/PirateDayCacheabilityMetadataConfigOverride.php
View source
<?php
namespace Drupal\config_override_test;
use Drupal\config_override_test\Cache\PirateDayCacheContext;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryOverrideInterface;
use Drupal\Core\Config\StorageInterface;
class PirateDayCacheabilityMetadataConfigOverride implements ConfigFactoryOverrideInterface {
public function loadOverrides($names) {
$overrides = [];
if (PirateDayCacheContext::isPirateDay()) {
if (in_array('system.theme', $names)) {
$overrides = $overrides + [
'system.theme' => [
'default' => 'pirate',
],
];
}
if (in_array('block.block.call_to_action', $names)) {
$overrides = $overrides + [
'block.block.call_to_action' => [
'settings' => [
'label' => 'Draw yer cutlasses!',
],
],
];
}
}
return $overrides;
}
public function getCacheSuffix() {
return 'PirateDayConfigOverrider';
}
public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) {
return NULL;
}
public function getCacheableMetadata($name) {
$metadata = new CacheableMetadata();
$metadata
->setCacheContexts([
'pirate_day',
])
->setCacheTags([
'pirate-day-tag',
])
->setCacheMaxAge(PirateDayCacheContext::PIRATE_DAY_MAX_AGE);
return $metadata;
}
}