Problem/Motivation
The data_policy module’s RedirectSubscriber adds a status message on every request when a new data policy is available, using:
$this->messenger->addStatus($this->t('We published a new version of the data protection statement...'));
However, this message is also added during AJAX requests, such as when using Views AJAX pagination or Facet filters, resulting in duplicate status messages being displayed to the user — once from the original page load, and again after each AJAX interaction.
This occurs because the RedirectSubscriber::checkForRedirection() method is invoked on every KernelEvents::REQUEST, regardless of the request type.
Steps to reproduce
1. Add a new Policy version, keep it non-required
2. Login as a user that should accept the policy
3. Execute any ajax request (e.g. Views pagination)
You should see the status message repeated along the results.
Proposed resolution
Add a conditional check to skip AJAX requests in the subscriber:
$request = $event->getRequest();
if ($request->isXmlHttpRequest()) {
return;
}
This ensures that status messages are only added during full page loads, not partial AJAX requests, avoiding duplication and improving UX consistency.
Remaining tasks
N/A
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Issue fork data_policy-3540437
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 #5
ribelTested and released in https://www.drupal.org/project/data_policy/releases/2.0.8