class HighContrastBlockView in High contrast 8
Provides a trusted callback to alter the system branding block.
Hierarchy
- class \Drupal\high_contrast\HighContrastBlockView implements RenderCallbackInterface
Expanded class hierarchy of HighContrastBlockView
See also
color_block_view_system_branding_block_alter()
File
- src/
HighContrastBlockView.php, line 13
Namespace
Drupal\high_contrastView source
class HighContrastBlockView implements RenderCallbackInterface {
/**
* #pre_render callback: Sets high contrast cacheability metadata on blocks.
*
* Scans all blocks to see if they depend on the system.theme.global cache tag.
* If so, also make them depend on the high contrast cacheability metadata.
*/
public static function preRender(array $build) {
$cacheable_metadata = CacheableMetadata::createFromRenderArray($build);
// Add cacheable data for blocks depending on config:system.site cache tags.
// Todo: The system branding block does not correctly declare its dependency
// on system.theme.global.
$tags = $cacheable_metadata
->getCacheTags();
if (in_array('config:system.site', $tags)) {
$config = \Drupal::config('high_contrast.settings');
// Always create a cache context for the no-whitelabel version.
$cacheable_metadata
->addCacheContexts([
'high_contrast',
]);
$cacheable_metadata
->addCacheableDependency($config);
// Add cacheable metadata.
$cacheable_metadata
->applyTo($build);
}
return $build;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
HighContrastBlockView:: |
public static | function | #pre_render callback: Sets high contrast cacheability metadata on blocks. |