class PirateDayCacheabilityMetadataConfigOverride in Drupal 9
Same name and namespace in other branches
- 8 core/modules/config/tests/config_override_test/src/PirateDayCacheabilityMetadataConfigOverride.php \Drupal\config_override_test\PirateDayCacheabilityMetadataConfigOverride
Test implementation of a config override that provides cacheability metadata.
Hierarchy
- class \Drupal\config_override_test\PirateDayCacheabilityMetadataConfigOverride implements ConfigFactoryOverrideInterface
Expanded class hierarchy of PirateDayCacheabilityMetadataConfigOverride
1 string reference to 'PirateDayCacheabilityMetadataConfigOverride'
- config_override_test.services.yml in core/
modules/ config/ tests/ config_override_test/ config_override_test.services.yml - core/modules/config/tests/config_override_test/config_override_test.services.yml
1 service uses PirateDayCacheabilityMetadataConfigOverride
- config_override_test.pirate_day_cacheability_metadata_override in core/
modules/ config/ tests/ config_override_test/ config_override_test.services.yml - Drupal\config_override_test\PirateDayCacheabilityMetadataConfigOverride
File
- core/
modules/ config/ tests/ config_override_test/ src/ PirateDayCacheabilityMetadataConfigOverride.php, line 13
Namespace
Drupal\config_override_testView source
class PirateDayCacheabilityMetadataConfigOverride implements ConfigFactoryOverrideInterface {
/**
* {@inheritdoc}
*/
public function loadOverrides($names) {
$overrides = [];
// Override the theme and the 'call_to_action' block on Pirate Day.
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;
}
/**
* {@inheritdoc}
*/
public function getCacheSuffix() {
return 'PirateDayConfigOverrider';
}
/**
* {@inheritdoc}
*/
public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) {
return NULL;
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata($name) {
$metadata = new CacheableMetadata();
$metadata
->setCacheContexts([
'pirate_day',
])
->setCacheTags([
'pirate-day-tag',
])
->setCacheMaxAge(PirateDayCacheContext::PIRATE_DAY_MAX_AGE);
return $metadata;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PirateDayCacheabilityMetadataConfigOverride:: |
public | function |
Creates a configuration object for use during install and synchronization. Overrides ConfigFactoryOverrideInterface:: |
|
PirateDayCacheabilityMetadataConfigOverride:: |
public | function |
Gets the cacheability metadata associated with the config factory override. Overrides ConfigFactoryOverrideInterface:: |
|
PirateDayCacheabilityMetadataConfigOverride:: |
public | function |
The string to append to the configuration static cache name. Overrides ConfigFactoryOverrideInterface:: |
|
PirateDayCacheabilityMetadataConfigOverride:: |
public | function |
Returns config overrides. Overrides ConfigFactoryOverrideInterface:: |