The "Sitewide Alert" block return an empty array if no alert exists

Created on 14 February 2025, about 2 months ago

Problem/Motivation

The "Sitewide Alert" block return an empty array if no alert exists.
But it should at list return a cache invalidation in order to render the sitewide_alert/init library and call the alerts endpoint.
In this way when a new alert is created from the back office the cache is invalidated and the necessary renderable array with the library is rendered from the block.

Steps to reproduce

- Enable the module
- Go to the front page for example in anonymous context
- From the back office add any new alert
- Go back to the front page in anonymous context, the alert is not shown

Proposed resolution

From the SitewideAlertRenderer.php return an entity list cache tag :

if (!$this->sitewideAlertManager->activeSitewideAlerts()) {
      return [
        '#cache' => ['tags' => ['sitewide_alert_list']],
      ];
    }

Or add the same cache tag in the dedicated block SitewideAlertBlock.php :

  /**
   * {@inheritdoc}
   */
  public function getCacheTags(): array {
    return Cache::mergeTags(parent::getCacheTags(), [
      'sitewide_alert_list',
    ]);
  }
πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024