Problem/Motivation
In warn-only mode, a single PDF upload triggers two identical sets of accessibility warning messages — one from the file constraint validator and one from the media entity hook. Editors see the same accessibility issues listed twice after every save.
Two code paths independently call messenger->addWarning() for the same upload with no coordination between them:
- Path 1 —
Pdfa11yConstraintValidator::showWarnings(): Whenblock_failed_uploadsis disabled (or the user has thebypass blocked pdf uploadspermission),validate()falls through toshowWarnings(), which calls$this->analyzer->analyze()and$this->messenger->addWarning(). This fires during the AJAX file upload and the warning appears inline in the form widget. - Path 2 —
Pdfa11yEntityHooks::runAccessibilityChecks():hook_media_insert/hook_media_updatefires after the entity saves and also calls$this->analyzer->analyze()and$this->messenger->addWarning(). This warning appears after the save redirect.
Because these fire in two separate HTTP requests (file upload AJAX, then entity save form submit), editors see the warning once inline on upload and then again on the page after saving.
Steps to reproduce
- Enable PDFa11y with Run accessibility checks on PDF upload on and Block uploads that fail accessibility checks off (warn-only mode).
- Upload a PDF that fails at least one accessibility check (e.g., an untagged PDF with no document title).
- Observe the inline warning that appears in the file widget immediately after upload.
- Click Save.
- Observe the messenger warnings on the resulting page.
Expected: Warning appears inline on upload; no additional warning after save.
Actual: Warning appears inline on upload, then the same warning appears again after save.
Proposed resolution
The inline warning on file upload is intentional and useful — it gives editors immediate feedback before they commit to saving. The duplicate after save is the problem.
Remove the messenger->addWarning() call from Pdfa11yEntityHooks::runAccessibilityChecks(), leaving analyze() and storeResults() in place. The entity hook's responsibility is to persist results to the database; messenger output is the validator's responsibility and fires at the right moment (AJAX upload) without needing to repeat after save.
This also removes the unused MessengerInterface and RendererInterface dependencies from Pdfa11yEntityHooks and updates pdfa11y.services.yml accordingly.
Remaining tasks
- Remove
messenger->addWarning()fromPdfa11yEntityHooks::runAccessibilityChecks() - Remove
MessengerInterfaceandRendererInterfacefromPdfa11yEntityHooksconstructor and service definition - Update kernel test to assert exactly one warning is added by the validator in warn-only mode
- Review
- Merge
User interface changes
Accessibility warnings will appear inline in the file widget immediately on upload as before, but will no longer repeat as a messenger warning after saving.
API changes
None. runAccessibilityChecks() is a protected method. The constructor signature of Pdfa11yEntityHooks changes (two arguments removed) but it is not part of the public API.
Data model changes
None.
Issue fork pdfa11y-3588856
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 #2
joshuamiComment #5
joshuami