[#3576066] Refresh JSON Editor schema when Update pattern is clicked in Layout Builder block config

Summary

Fixes the JSON Editor in the Patternkit block configuration form so it refreshes when "Update pattern" is clicked in Layout Builder. The form now uses the current schema from the pattern entity on each build and invalidates the cached editor settings when the schema changes.

Changes

JsonEditorForm (src/Element/JsonEditorForm.php)

  • In buildEditorForm(), set #schema from the current pattern entity (getSchema()) before calling editorSettings() so rebuilt forms always use the latest schema.
  • In editorSettings(), recompute cached settings when the incoming schema differs from the cached schemaJson (in addition to when the cache is empty).

Unit tests (tests/src/Unit/Element/JsonEditorFormTest.php)

  • Add getSchema() mock in testBuildEditorForm() to satisfy the new call in buildEditorForm().
  • Add testEditorSettingsReflectSchemaChangeOnSecondBuild() to assert the same element instance passes the new schema to the editor on a second build.
  • Fix line length and add @param annotations to the editorSettings() docblock.

Functional JavaScript tests (tests/src/FunctionalJavascript/LayoutBuilderBlockUpdateTest.php)

  • Add testBlockUpdateRefreshesSchemaFields() to assert that after clicking "Update pattern", the JSON Editor shows the current schema (e.g. current field labels) instead of the previous cached schema.

Testing

Manual

  1. Add a Patternkit Example block to a node layout and save.
  2. Edit example.json (e.g. add a new property or change a field title) and run drush patternkit:cache:clear.
  3. Open the block configuration; confirm "Update pattern schema and template" and the "Update pattern" button appear.
  4. Click "Update pattern"; confirm the success message and that the JSON Editor refreshes (new or renamed fields visible) without leaving the form or reloading.

Automated

  • ddev phpunit tests/src/Unit/Element/JsonEditorFormTest.php
  • ddev phpunit tests/src/FunctionalJavascript/LayoutBuilderBlockUpdateTest.php

Closes #3576066.

Merge request reports

Loading