From 869dd1390385a18f64bfc2c0244a451526fd7e9a Mon Sep 17 00:00:00 2001 From: Andy Broomfield Date: Fri, 31 May 2024 18:44:16 +0100 Subject: [PATCH] Re-add the getCacheContexts method to localgov alert banner Fix #327 Part revert #325 Restores the getCacheContexts method as that is what is called each time to determine the cache contexts each time the block is rendered. --- src/Plugin/Block/AlertBannerBlock.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Plugin/Block/AlertBannerBlock.php b/src/Plugin/Block/AlertBannerBlock.php index 5e62de6..e04cacc 100644 --- a/src/Plugin/Block/AlertBannerBlock.php +++ b/src/Plugin/Block/AlertBannerBlock.php @@ -146,9 +146,7 @@ public function build() { // Render the alert banner. $build = []; - $contexts = []; foreach ($published_alert_banners as $alert_banner) { - $contexts = Cache::mergeContexts($contexts, $alert_banner->getCacheContexts()); // Only add to the build if it is visible. // @see #154. @@ -157,7 +155,6 @@ public function build() { ->view($alert_banner); } } - $build['#cache']['contexts'] = $contexts; return $build; } @@ -227,6 +224,17 @@ protected function mapTypesConfigToQuery() : array { }); } + /** + * {@inheritdoc} + */ + public function getCacheContexts() { + $contexts = []; + foreach ($this->getCurrentAlertBanners() as $alert_banner) { + $contexts = Cache::mergeContexts($contexts, $alert_banner->getCacheContexts()); + } + return Cache::mergeContexts(parent::getCacheContexts(), $contexts); + } + /** * {@inheritdoc} */