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} */