Skip to content

Commit

Permalink
Merge pull request #328 from localgovdrupal/fix/1.x-327-alert-banner-…
Browse files Browse the repository at this point in the history
…block-cache-contexts

Re-add the getCacheContexts method to block
  • Loading branch information
finnlewis authored Jun 4, 2024
2 parents e4aff62 + 869dd13 commit 427d5f6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Plugin/Block/AlertBannerBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -157,7 +155,6 @@ public function build() {
->view($alert_banner);
}
}
$build['#cache']['contexts'] = $contexts;
return $build;
}

Expand Down Expand Up @@ -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}
*/
Expand Down

0 comments on commit 427d5f6

Please sign in to comment.