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.jsonSubmit 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.jsbeforeSerialize / 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.jsbeforeSubmit 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

  1. Audit js/patternkit.jsoneditor.js for 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.
  2. Guard beforeSerialize / beforeSubmit chaining with typeof checks to prevent errors when those handlers are not defined by Drupal.
  3. Fix the beforeSubmit form value lookup to use the actual name attribute of the schema_instance_config hidden field rather than a hardcoded string.
  4. Update or remove the onSubmit method 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

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

slucero created an issue. See original summary.

slucero’s picture

Title: Simplify full-page block config code paths and fix JavaScript submit handling in patternkit.jsoneditor.js » Fix beforeSubmit form value lookup in patternkit.jsoneditor.js
Issue summary: View changes
Status: Active » Needs review

During 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

  • Fixed the beforeSubmit form value lookup in js/patternkit.jsoneditor.js from settings[instance_config] to settings[configuration].
  • Added clarifying comments in tests/src/Functional/PatternUpdateTest.php to document that the full-page block config URL usage in those tests is intentional for PHP-only coverage.

Decision notes against the proposed resolution

  1. onSubmit removal / full-page branch removal: not implemented in this MR. The ajax === undefined + onSubmit path was audited and retained.
  2. beforeSubmit lookup correction: implemented.
  3. typeof guards for handler chaining: no change required; guards were already present on 9.1.x.
  4. Audit of full-page-only behavior: completed. JS full-page handling remains in place; PHP-side block handling was confirmed context-agnostic.

Files changed

  • js/patternkit.jsoneditor.js — corrected beforeSubmit field name lookup.
  • tests/src/Functional/PatternUpdateTest.php — comment-only clarifications (no behavioral test changes).

Verification

  • ddev exec vendor/bin/phpstan analyse --verbose — PASS
  • ddev exec vendor/bin/phpunit tests/src/Functional/PatternUpdateTest.php — PASS (2 tests, 22 assertions)

MR !184 is published and CI has passed.

slucero’s picture

Status: Needs review » Reviewed & tested by the community

Reviewed and approved internally. Ready for merge.

  • slucero committed ee33c994 on 9.1.x
    [#3577380] Fix beforeSubmit form value lookup to use correct field name
    

  • slucero committed ee33c994 on fix-flaky-ckeditor-test
    [#3577380] Fix beforeSubmit form value lookup to use correct field name
    
slucero’s picture

Status: Reviewed & tested by the community » Fixed

Merged for inclusion in the 9.1.3 release.
See [##3542304].

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.

Status: Fixed » Closed (fixed)

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