Problem/Motivation
The Patternkit block config form can be opened in two ways in Layout Builder: as the standard off-canvas sidebar dialog (the primary path), or as a full-page/standalone form (reached via browser navigation rather than the Layout Builder AJAX overlay — e.g. opening the config link in a new tab). The full-page path was never formally tested or documented as a supported workflow, but some code in js/patternkit.jsoneditor.js was written with it in mind and continues to reference it explicitly.
During work on issue #3576066 (JSON Editor schema refresh), the full-page path was evaluated and intentionally excluded from scope. Supporting it correctly requires detecting dialog vs. full-page context at AJAX callback time, restoring native form submit behavior after a rebuild, and accommodating edge cases across validation and redirect flows. That complexity does not justify the editor impact: reaching the full-page form requires deliberate steps outside the normal editing path and is unlikely to be encountered in ordinary content workflows.
The following specific code areas were identified as candidates for simplification or removal:
js/patternkit.jsoneditor.js — onSubmit handler. The method comment states it "will only execute in full-page views of the JSON Editor form." If the full-page path is not supported, this handler and its comment should be reviewed to determine whether it is still needed or can be removed.
js/patternkit.jsoneditor.js — beforeSerialize / beforeSubmit chaining. When hooking into Drupal's AJAX lifecycle, the original ajax.beforeSerialize and ajax.beforeSubmit handlers are called unconditionally via .apply() even when they are undefined. This can throw when Drupal has not defined those handlers. These call sites should guard with a typeof check.
js/patternkit.jsoneditor.js — beforeSubmit form value lookup. The beforeSubmit hook searches formValues for an element named settings[instance_config]. In the block plugin form context, the jsoneditor_form element's #parents produce the field name settings[configuration], not settings[instance_config], so this lookup never matches and the value update in beforeSubmit is ineffective. The lookup should use the actual field's name attribute.
Proposed resolution
- Audit
js/patternkit.jsoneditor.jsfor code paths that exist solely or primarily to support full-page (non-dialog) form submission; remove or simplify them if the full-page path is not being maintained. - Guard
beforeSerialize/beforeSubmitchaining withtypeofchecks to prevent errors when those handlers are not defined by Drupal. - Fix the
beforeSubmitform value lookup to use the actualnameattribute of theschema_instance_confighidden field rather than a hardcoded string. - Update or remove the
onSubmitmethod and its comment if the full-page submission path it targets is confirmed out of scope.
Remaining tasks
All tasks assessed and resolved. See update comment below for findings on each item.
API changes
None anticipated. Changes are internal JavaScript behavior only.
Release notes snippet
Fixed a bug in the JSON Editor beforeSubmit handler where it looked up settings[instance_config] instead of settings[configuration], which prevented the latest editor value from being serialized before submission in full-page block config flows.
Issue fork patternkit-3577380
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 #3
sluceroDuring implementation, this issue was narrowed to a targeted fix and an explicit audit of the originally proposed scope.
Workflow support clarification
The first-class supported editing workflow is the Layout Builder sidebar/off-canvas tray flow. Non-AJAX/full-page block config access is not the focus of current Patternkit editor behavior work and is not treated as a primary supported path for new feature development.
What was implemented
beforeSubmitform value lookup injs/patternkit.jsoneditor.jsfromsettings[instance_config]tosettings[configuration].tests/src/Functional/PatternUpdateTest.phpto document that the full-page block config URL usage in those tests is intentional for PHP-only coverage.Decision notes against the proposed resolution
onSubmitremoval / full-page branch removal: not implemented in this MR. Theajax === undefined+onSubmitpath was audited and retained.beforeSubmitlookup correction: implemented.typeofguards for handler chaining: no change required; guards were already present on9.1.x.Files changed
js/patternkit.jsoneditor.js— correctedbeforeSubmitfield name lookup.tests/src/Functional/PatternUpdateTest.php— comment-only clarifications (no behavioral test changes).Verification
ddev exec vendor/bin/phpstan analyse --verbose— PASSddev exec vendor/bin/phpunit tests/src/Functional/PatternUpdateTest.php— PASS (2 tests, 22 assertions)MR !184 is published and CI has passed.
Comment #4
sluceroReviewed and approved internally. Ready for merge.
Comment #7
sluceroMerged for inclusion in the 9.1.3 release.
See [##3542304].