[#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#schemafrom the current pattern entity (getSchema()) before callingeditorSettings()so rebuilt forms always use the latest schema. - In
editorSettings(), recompute cached settings when the incoming schema differs from the cachedschemaJson(in addition to when the cache is empty).
Unit tests (tests/src/Unit/Element/JsonEditorFormTest.php)
- Add
getSchema()mock intestBuildEditorForm()to satisfy the new call inbuildEditorForm(). - Add
testEditorSettingsReflectSchemaChangeOnSecondBuild()to assert the same element instance passes the new schema to the editor on a second build. - Fix line length and add
@paramannotations to theeditorSettings()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
- Add a Patternkit Example block to a node layout and save.
- Edit
example.json(e.g. add a new property or change a field title) and rundrush patternkit:cache:clear. - Open the block configuration; confirm "Update pattern schema and template" and the "Update pattern" button appear.
- 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.phpddev phpunit tests/src/FunctionalJavascript/LayoutBuilderBlockUpdateTest.php
Closes #3576066.