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',
]);
}
Issue fork sitewide_alert-3506754
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
jmaxant commentedComment #5
jmaxant commentedHi there,
I just pushed a fix and created a MR with said changes (basically what @guenole suggested).
Comment #6
smustgrave commentedLeft a comment on the MR, wonder how hard it would be to add a test case for this too.
Comment #7
socialnicheguru commentedComment #9
smustgrave commentedComment #12
loopy1492 commentedThis seems to have worked for us, however it doesn't seem to be in the most recent release. This seems to be a pretty important issue and warrants a new release. We have, for now, patched it.