Problem/Motivation

A text format whose Ace Editor settings are stored flat, without the fieldset wrapper, raises six PHP messages on every render of a text format element:

Warning: Undefined array key "fieldset" in Drupal\ace_editor\Plugin\Editor\AceEditor->getLibraries() (line 165)
Warning: Trying to access array offset on null in Drupal\ace_editor\Plugin\Editor\AceEditor->getLibraries() (line 165)
Deprecated function: trim(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\ace_editor\Plugin\Editor\AceEditor->getLibraries() (line 165)
Warning: Undefined array key "fieldset" in Drupal\ace_editor\Plugin\Editor\AceEditor->getLibraries() (line 166)
Warning: Trying to access array offset on null in Drupal\ace_editor\Plugin\Editor\AceEditor->getLibraries() (line 166)
Deprecated function: trim(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\ace_editor\Plugin\Editor\AceEditor->getLibraries() (line 166)

settingsForm() and getJsSettings() both accept the two shapes the module can store: settings saved through the configuration form are nested under fieldset, while configuration created programmatically, by a recipe, a config import or an older release keeps them at the top level. getLibraries() is the only one that does not, and indexes ['fieldset']['theme'] and ['fieldset']['syntax'] unconditionally.

Beyond the messages the theme is also wrong: $theme and $mode end up empty, the library existence check fails, and the format is rendered with the site-wide default theme instead of the one it is configured with.

A node edit form attaches the editor of every text format the user may use, so a single flat-configured format is enough to fill an unrelated form with these messages.

Steps to reproduce

  1. Enable Ace Editor and assign it as the text editor of a text format.
  2. Store that format's editor settings flat, as a recipe or a configuration import would:
    drush php:eval '\Drupal\editor\Entity\Editor::load("full_html")->setSettings(["theme" => "chrome", "syntax" => "html"])->save();'
  3. Visit any node edit form that offers that format.

Reproduced on Drupal 10.6.15 and Drupal 11.4.5, PHP 8.4.

Proposed resolution

Move the shape handling getJsSettings() already carries into a shared instanceSettings() helper, and read the theme and syntax through it in getLibraries(), so both shapes are normalised in one place and the two methods cannot drift apart again.

Kernel coverage is added for the libraries of both shapes, for the defaults of empty settings, and for the absence of any raised warning.

Screenshots

A node form offering a text format whose editor settings are stored flat, before and after the fix.

 the same form with no messages and the editor attached.

Remaining tasks

  • ✅ File an issue
  • ✅ Addition/Change/Update/Fix
  • ✅ Testing to ensure no regression
  • ✅ Automated unit/functional testing coverage
  • ➖ Developer Documentation support
  • ➖ User Guide Documentation support
  • ➖ UX/UI designer responsibilities
  • ➖ Accessibility and Readability
  • ❌ Reviewed by a human
  • ❌ Code review by maintainers
  • ❌ Full testing and approval
  • ❌ Credit contributors
  • ❌ Review with the product owner
  • ❌ Update Release Notes
  • ❌ Release

User interface changes

  • A text format configured with flat settings is rendered with its own theme and syntax instead of the site-wide defaults.

API changes

  • N/A

Data model changes

  • N/A

Release notes snippet

  • Fixed the editor settings of a text format stored without the fieldset wrapper raising warnings and a trim() deprecation on every render, and the format being rendered with the default theme.
CommentFileSizeAuthor
#5 ace-fieldset-comparison.png258.52 KBrajab natshah

Issue fork ace_editor-3618848

Command icon 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

rajab natshah created an issue. See original summary.

  • rajab natshah committed 7dedcf4f on 2.0.x
    fix: #3618848 Read the editor settings of both stored shapes when...
rajab natshah’s picture

Issue summary: View changes
rajab natshah’s picture

Issue summary: View changes
StatusFileSize
new258.52 KB

Added a before and after screenshot of a form offering a flat-configured text format.

rajab natshah’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

rajab natshah’s picture

Issue tags: +ace_editor-2.0.4

✅ Released ace_editor-2.0.4

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.