Problem/Motivation

Patternkit introduces an admin-configurable enforcement toggle (render_validation_on_save, default TRUE) in #3589846: Add validity stamp infrastructure and save-time validation enforcement for PatternkitBlock entities that blocks saving a PatternkitBlock when its content fails server-side JSON Schema validation. The toggle is designed as a safety valve for sites that accumulated legacy-invalid content before validation was introduced: an operator can disable enforcement temporarily, let editors re-save blocks through the browser UI, then re-enable enforcement once remediation is complete.

The toggle is ineffective for its primary intended use case. When an editor opens a block in Layout Builder, the JSON Editor library validates the stored content immediately and blocks form submission if errors are found. This happens entirely client-side, before the form reaches the server. The server-side toggle never applies. Editors are stuck: they cannot save any change (including unrelated edits such as updating body text) without fixing every validation error in the block, including fields they may not know how to correct.

Steps to reproduce

  1. Install Patternkit with a pattern that has a required field.
  2. Save a PatternkitBlock with invalid content via Drush pkset or the entity API to simulate a legacy-invalid state.
  3. Go to Administration > Configuration > Patternkit and disable Validate on save (render_validation_on_save = FALSE).
  4. Open the affected block in Layout Builder.
  5. Make an unrelated change (e.g., update a body text field).
  6. Click Update.

Observed: JSON Editor blocks submission. The form does not reach the server. The toggle has no effect.

Expected: With the toggle off, the editor can save the block. Validation issues are displayed as non-blocking warnings so the editor is informed but not stopped.

Proposed resolution

Make the client-side validation gates in patternkit.jsoneditor.js toggle-aware. When the toggle is off, submission with errors is intercepted once to show non-blocking warnings; a second click proceeds. When the toggle is on (the default), behavior is unchanged.

Config delivery

JsonEditorFormBuilder::buildEditorForm() adds renderValidationOnSave to drupalSettings.patternkitEditor via the existing settings pipeline. JsonEditorForm::defaultEditorSettings() injects the value into #attached.

Submit-boundary intercept (toggle off)

On first submit with errors, validateBeforeAjaxSubmit() or onSubmit() intercepts and:

  • Inserts a messages--warning block above the submit button
  • Relabels the button from Update to Save with issues
  • Adds a CSS class to the editor container to shift inline indicators from red to amber

A second click serializes editor state via saveSchema() and submits. Warning state persists until all issues are resolved or the form closes; resolution fully reverts the button and message.

Custom validator

patternkitRequiredStringValidator continues to run unconditionally. The gate functions, not the validator, decide whether to block.

Unchanged behavior (toggle on)

No change to current behavior.

  • Validation errors block submission.
  • The warning message, button relabel, and amber indicators are never shown.

Status report warning

hook_requirements in patternkit.install emits a REQUIREMENT_WARNING on admin/reports/status while render_validation_on_save is FALSE.

Tests

ValidationToggleTest covers five FunctionalJavascript scenarios: toggle-off submit proceeds; toggle-on blocks; toggle-off with valid content saves normally; editor fixes issues and warning clears; warning re-triggers after a fresh validation failure.

Remaining tasks

  • Review and test the merge request.
  • CI validation.

User interface changes

  • Warning message block: A messages--warning message block appears above the submit button when the toggle is off and a submit attempt finds validation errors. The message is removed when all issues are resolved.
  • Button relabel: The submit button changes from Update to Update with issues in the warning state and reverts when all issues are resolved.
  • Status report warning: A new warning entry appears on admin/reports/status when render_validation_on_save is FALSE.

Introduced terminology

None.

API changes

JsonEditorFormBuilder::buildEditorForm() adds a renderValidationOnSave boolean to the drupalSettings.patternkitEditor object. This is a new key in an existing settings namespace; no existing keys are changed or removed.

Data model changes

None.

Release notes snippet

Patternkit now makes the client-side JSON Editor validation gate toggle-aware. When the save-time enforcement toggle is disabled (render_validation_on_save = FALSE), editors can save blocks with validation issues through the Layout Builder UI. Validation errors are displayed as non-blocking warnings: a message block appears above the submit button and the button relabels to Save/Update with issues, so the editor is informed but not stopped. When the toggle is on (the default), behavior is unchanged and validation errors continue to block submission. A warning also appears on the site status report while enforcement is disabled, reminding administrators that invalid content can be saved until re-enabled.

Known issues

  • Stale toggle value: The toggle value is delivered to JavaScript at form render time via drupalSettings. If an administrator changes the toggle while an editor has a block form open, the open form uses the stale value until the page is refreshed. This is inherent to how drupalSettings works and affects only the narrow window between a settings change and a page reload.

Issue fork patternkit-3594479

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

Issue summary: View changes
Status: Active » Needs review

Ready for review and testing.

  • e3f9f937 committed on 9.1.x
    feat: #3594479 Toggle-aware client-side validation with warning UX
    
    When...

  • 74999c8b committed on 9.1.x
    feat: #3594479 Expose validation toggle to client-side and add status...

  • slucero committed f47313d3 on 9.1.x
    feat: #3594479 Client-side validation toggle integration for editorial...
slucero’s picture

Status: Needs review » Fixed

Merged for inclusion in release 1.3.

See #3542304: Patternkit 9.1.3 Release Plan.

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.