Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.Problem/Motivation
The current implementation (9.1.x-beta7 and earlier) of JSON Editor in the module loads scripts and related assets for JSON Editor asynchronously via JavaScript instead of through attachments in the form render array when assembling the form. This method complicates both the JavaScript and server-side implementation by requiring the LibraryStream service to produce URLs for these assets to be exposed via JS settings, and the JS logic to parse these URLs and add them on the page.
Changes in the underlying systems for managing these assets also lead to maintenance issues like the one causing #3381549: JSON Editor theme assets do not load on Drupal 10.1.
Proposed resolution
- Deprecate LibraryStream service
- Deprecate PatternkitStream service
- Attach JSON Editor assets in form building process server-side
- Remove asynchronous asset loading logic from JS
From the front-end, these changes should remain pretty transparent and focus on confirming the continuity of existing features.
- Selected themes and icon libraries should load and display as expected in both the off-canvas tray and full-page view of the block edit form.
- Creation of content on new blocks should be saved and displayed as expected.
- Editing existing blocks should properly prepopulate existing content into the form.
- Saving changes to existing blocks should be properly reflected on save.
- Media library integration supports adding and changing selected media.
User interface changes
- Removed unsupported JSON Editor theme options:
- barebones
- html
- Removed unsupported JSON Editor icon library option: jqueryui
- Removed unsupported JSON Editor theme configuration options:
- Additional editor theme CSS
- Additional editor theme JS
API changes
- Deprecated LibraryStream service for removal in 9.1.0 release
- Deprecated PatternkitStream service for removal in 9.1.0 release
- New
jsoneditor_formform element - New
patternkit.jsoneditor.form_builderservice to help build JSON Editor form \Drupal\patternkit\JSONSchemaEditorTraitis now deprecated and replaced. Will be removed in v9.1.0 releasePatternLibraryPluginInterface::getEditor()is deprecated and will be removed in v9.1.0 release. UsegetPatternEditor()instead.
Data model changes
None
Known issues
- Selected icon libraries are not properly rendered when viewing the pattern editor form in the off-canvas tray due to conflicts with core CSS resets in the off-canvas tray. This was already the case in prior releases and will remain blocked until a solution like #3395617: Add a class to opt-out of off-canvas resets in contrib is provided.
Issue fork patternkit-3386854
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 #4
krisahil commented@slucero, I started work to support these changes. The MR, as it stands now, loads the JSON Editor theme assets as a Drupal library, using
#attached, instead of manually adding the scripts and styles to the DOM. On one site, this change has made loading the CSS and JS much more reliable (the manual method loaded CSS and JS in unpredictable order, which led to race conditions, evidenced in CKEditor 5 integration).Comment #5
sluceroThanks for getting this started @krisahil! I looked over the code so far and it all looks good. One thing I'd look into as part of this as well is whether we can remove the shadow dom versions and related checks altogether now that we've removed shadow dom support in the beta 9 release.
Comment #6
sluceroComment #7
sluceroComment #8
sluceroComment #9
slucero@krisahil, thanks for the heads up on the regression. I'll have to look into that more closely.
Regarding this, yes the block form may also be opened in a full-page view instead of in the sidebar tray. The simplest way to do this that I've found for testing is to right-click the link for one of the block edit forms and select to open it in a new tab. This will open up the full-page form and redirect you back to the layout edit page upon submission.
Applying the
#patternkit-editor-targetID is a shortcut that was used to have a consistent target for the form to instantiate within and to allow the cygnet theme styles to target more directly without being reliant specifically on the markup for the sidebar tray. This would of course conflict if multiple editors are instantiated on a page at once, but I suspect we'll have a few additional issues in that scenario to overcome as well.Comment #10
minsharm commentedI have retested it and observed an issue related to "Edit JSON" and "Properties" button
Steps to reproduce :
Actual Results:
With this change, "properties" button is always visible and "Edit Json" button is always invisible irrespective of the JSON pattern library settings.
Expected Results:
"properties" button should be invisible and "Edit Json" button should be visible as per the above JSON pattern library settings mentioned in Steps.
Comment #11
sluceroThere was an issue with naming mismatches for the settings. This should be fixed and ready for testing again.
Comment #12
sluceroComment #13
sluceroComment #15
sluceroMerged for inclusion in the 9.1.0-beta10 release!