fix: #2999328 Isolate Ace Format settings per field and take the syntax from a field
Issue: https://www.drupal.org/project/ace_editor/issues/2999328
Rebased onto current 2.0.x (the branch was five commits behind and conflicted with the hook conversion and the settings fixes merged since, which is why the web rebase could not resolve it). Andrew Morton's feature set and Dominik Wille's original design are kept - credit to both - with the isolation mechanism changed and the reported regressions fixed.
Settings now travel on each field's wrapper (data-ace-formatter-settings) instead of a drupalSettings bucket keyed by a generated identifier. Html::getUniqueId() is a per-request counter while entity render arrays are render-cached as one unit, so two entities rendered in two requests both get ace-formatter-body-0; a later page showing both from cache ends up with a single bucket and the reported bug returns on any listing page. Carrying the settings in the markup is cache-safe by construction.
The three "Undefined array key" warnings reported in #15 are fixed. defaultSettings() now falls back to hardcoded values for syntax_field, modelist and inline (config/install is not re-imported on an existing site), settingsForm() and settingsSummary() read them defensively, and ace_editor.post_update.php adds them to the active configuration.
Other changes from the previous revision of this branch:
- The update moved from
hook_update_N()tohook_post_update_NAME()withConfigEntityUpdater, which is where config-entity updates belong, and it no longer leaves a per-display flag that reads as more than it does. getSyntaxOptions()offers only text-like fields; an image or reference field cannot name a syntax mode.- Only the keys the JavaScript reads are sent to the browser, so a display carrying the option lists of an older release does not ship them to every visitor.
js/formatter.jsusesonce(), honoursmodelistthroughace/ext/modelistandinlinethroughsetMode({path, inline}), reuses an existing editor element rather than stranding a stale one after an AJAX rebuild, and no longer has the fallback that handed Aceace/theme/undefinedwhen the lookup missed.- The formatter library depends on
core/once;modelistis in the spelling dictionary; the configuration schema covers the three new keys.
Tests: AceFormatterMultipleFieldsTest - two fields on one entity keeping their own theme and syntax; the same field on two entities with the identifier counter reset between renders (the render-cache case); one payload per delta; the option lists never reaching the browser; the syntax taken from a configured field; and the settings summary rendering on settings that predate the new options.
Verified locally: kernel+unit suite green, PHPStan clean, PHPCS clean, no conflicts with 2.0.x.
AI-Generated: Yes
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