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

  1. Create or use a Patternkit schema with a non-image object key that still follows a *.src shape, for example custom_image.src, custom_image.alt, custom_image.width, custom_image.height, and custom_image.title.
  2. Open Layout Builder and add the block using that schema.
  3. Click Select/Upload image for the non-image key's src field.
  4. Choose an image and click Insert selected.
  5. 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.src to .src while preserving silent-skip behavior when sibling fields are absent.

Test coverage

  • modules/patternkit_media_library/tests/src/FunctionalJavascript/JsonEditorMediaSelectionTest.php: add testImageAttributesPopulateOnSelectionForNonImageObjectKeys() to verify selection-driven attribute population for custom_image and alternate_media key paths.
  • tests/modules/patternkit_test/lib/patternkit_test/components/custom_key_image_attributes_test/custom_key_image_attributes_test.json and tests/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-image object keys for verification.
  • Retain existing blur-driven coverage (testImageAttributesFetchOnBlur()) as adjacent validation while this issue targets selection-flow opener behavior.

Related issues

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.

Issue fork patternkit-3593772

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

Status: Active » Needs review
slucero’s picture

This 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.

slucero’s picture

Status: Needs review » Reviewed & tested by the community

Tested and approved internally for merging by @minsharm.

  • slucero committed 4ef4b7c5 on 9.1.x
    feat: #3593772 Media library selection only populates sibling image...
slucero’s picture

Status: Reviewed & tested by the community » Fixed

Merged 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.

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.

  • slucero committed 4ef4b7c5 on linting-configuration-cleanup
    feat: #3593772 Media library selection only populates sibling image...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.