Problem/Motivation
Selecting an image from the media library in URL mode (media_token=0) currently populates sibling image attributes (for example alt, title, width, height) only when the target widget path ends with .image.src. Schemas using other valid object keys such as custom_image.src or alternate_media.src receive the src value but miss sibling attribute population.
Steps to reproduce
- Create or use a Patternkit schema with a non-
imageobject key that still follows a*.srcshape, for examplecustom_image.src,custom_image.alt,custom_image.width,custom_image.height, andcustom_image.title. - Open Layout Builder and add the block using that schema.
- Click Select/Upload image for the non-
imagekey'ssrcfield. - Choose an image and click Insert selected.
- Observe the resulting field values.
Note: This patch adds the [Patternkit] Custom key image attributes test pattern in patternkit_test; when patternkit_test is enabled, use that pattern to verify the fix directly instead of reproducing from a separate feature-branch-only schema.
Proposed resolution
Update opener-side gating to use a generic *.src suffix check instead of hard-coding .image.src, then cover selection-driven behavior with a regression test that validates multiple non-image object keys.
Code changes
modules/patternkit_media_library/src/MediaLibraryJSONLibraryOpener.php: change sibling-population gate from.image.srcto.srcwhile preserving silent-skip behavior when sibling fields are absent.
Test coverage
modules/patternkit_media_library/tests/src/FunctionalJavascript/JsonEditorMediaSelectionTest.php: addtestImageAttributesPopulateOnSelectionForNonImageObjectKeys()to verify selection-driven attribute population forcustom_imageandalternate_mediakey paths.tests/modules/patternkit_test/lib/patternkit_test/components/custom_key_image_attributes_test/custom_key_image_attributes_test.jsonandtests/modules/patternkit_test/lib/patternkit_test/components/custom_key_image_attributes_test/custom_key_image_attributes_test.twig: add a reusable test pattern with two non-imageobject keys for verification.- Retain existing blur-driven coverage (
testImageAttributesFetchOnBlur()) as adjacent validation while this issue targets selection-flow opener behavior.
Related issues
- Historical context: #3370254: Adding an image url via Media Library should also populate image alt, height, and width text fields.
Remaining tasks
- Review and test the merge request.
- CI validation.
- Confirm FunctionalJavascript coverage passes in local and CI environments.
User interface changes
None.
Introduced terminology
None.
API changes
None.
Data model changes
None.
Release notes snippet
Media-library image selection now populates sibling image attributes for any schema path ending in *.src, not only paths ending in *.image.src, improving compatibility with custom schema object key names.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3593772--broaden-sibling-attributes--functional-only.patch | 1.31 KB | slucero |
Issue fork patternkit-3593772
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 #3
sluceroComment #4
sluceroThis work is now ready for review and testing. For convenient access, I'm also attaching a functional-changes-only patch for inclusion in projects as needed. Tests and related pattern additions are intentionally excluded from this to keep the footprint minimal.
Comment #5
sluceroTested and approved internally for merging by @minsharm.
Comment #7
sluceroMerged for inclusion in the 9.1.3 release.
See #3542304: Patternkit 9.1.3 Release Plan.
For sites wanting to install the functionality prior to the release, a patch is also available as an attachment to this issue.