fix: #3618865 Return an empty attribute set for a tag without attributes
Fixes #3618865.
tagAttributes() returned FALSE when an <ace> tag carried no attributes, and process() iterates over that return value without a guard, so a tag written in the documented basic form raised a warning on every render:
Warning: foreach() argument must be of type array|object, false given in
Drupal\ace_editor\Plugin\Filter\AceFilter->process() (line 141)A tag with no attributes is how docs/index.md and docs/1-users/3-filter.md both introduce the filter, so this is the simplest case the module offers. The snippet still rendered - the attribute loop was skipped, which is right when there are no attributes - so the effect was a warning on every render rather than broken output.
The existing unit test testNoAttributesReturnsFalse() asserted that FALSE, which is why it survived: the contract was pinned by a test while no caller could handle it.
Changes
tagAttributes()returns an empty array for a tag without attributes. Iterating it is a no-op, and an existingif (!$attributes)check behaves the same because an empty array is falsy.- The unit test now asserts the empty array, for
<ace>and for<ace >. - New kernel test
AceFilterProcessTest: processes a bare tag, an attributed tag, both on one page, and text with no tag, asserting under an error handler that nothing is raised. It reads the collected settings from the result's attachments rather than a static.
Verification
Reproduced and fixed on Drupal 11.4.5, PHP 8.4:
- A node with
<ace>const value = 1;</ace>: warning before, none after, 30-line snippet still rendered and the tag replaced. - A node carrying a bare tag and an attributed one together: no warnings, and the attributed tag still resolves
ace/mode/phpwhile the bare one keeps the filter's configuredjavascript, so per-tag overrides are intact.
Local gate green: PHPUnit 46 tests / 128 assertions, phpcs (Drupal, DrupalPractice), cspell, PHPStan. PHPStan is approximated locally, since this repository ships only a baseline and the configuration comes from the drupalci templates, so that job gates on this pipeline.
Checkpoints:
- File an issue
- Addition/Change/Update/Fix
- Testing to ensure no regression
- Automated unit testing coverage
- Automated functional testing coverage
- UX/UI designer responsibilities
- Readability
- Accessibility
- Performance
- Security
- Developer Documentation
- User Guide Documentation
- Reviewed by human
- Code review by maintainers
- Full testing and approval
- Credit contributors
- Review with the product owner
- Release notes snippet
- Release
AI-Generated: Yes