When using Linked field in combination with the picture element (For example when displaying media items with picture module) linked field wraps the link around the nested image element which breaks the markup. As it is cleaner to wrap the whole picture tag anyway the attached patch does exactly that.

Comments

yannickoo’s picture

Status: Needs review » Needs work

We should create an array for that instead of having 1k if's, something like a blacklist.

archnode’s picture

StatusFileSize
new2.94 KB

How about this? Using a simple array to map certain elements to a handler. We could make the array alterable or event implement kind of a linked_field_handler_info(), but I'm not sure if that is necessary, what do you think?

yannickoo’s picture

Assigned: Unassigned » yannickoo

Yeah something like this :) A small drupal_alter would be enough I think.. I will work on this later, thanks for the patch.

  • yannickoo committed f5d472c on 7.x-1.x authored by archnode
    Issue #2319165 by archnode: Fixed Linked Field breaks picture markup.
    
yannickoo’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Assigned: yannickoo » Unassigned
Status: Needs work » Patch (to be ported)
jon@s’s picture

Has this been ported into the D8 version yet?

pixelmord’s picture

StatusFileSize
new1.83 KB

In the D8 version there is an additional problem that the the render array of the filed is replaced completely.
See attached patch that addresses both problems, but beware: I did only test this with responsive image fields so far.

m.abdulqader’s picture

The last patch worked well, but when you edit the content the picture markup will break. Remove cache it will work.

Thanks

abu-zakham’s picture

StatusFileSize
new1.83 KB

I have re-rolled the patch in #7 to work with the latest development version.

abu-zakham’s picture

Status: Patch (to be ported) » Needs review

The last submitted patch, 2: picture-support-2319165-2.patch, failed testing.

weseze’s picture

Had a similar issue with the use of the drimage module. It generates inline svg data in the src attributes for images. And when a destination is set via linked_field on these images, linked_field changes the inline svg data. Some characters are html encoded, making the inline svg data not work anymore.

Your patch in #9 fixed the problem.

mariacha1’s picture

StatusFileSize
new1.95 KB
new720 bytes

Patch #9 was breaking when we had caching enabled, since media entities are cached. I'm including a small change to set the value of the ['#markup'] to a proper Markup class. It's possible this is only a problem with Media Entity media items, and not Core media items.

sonfd’s picture

Patch #13 is working for me with contrib media entity items.

johnlutz’s picture

#13 works with media

qsDave’s picture

Just tried this module and it prevented the gears from working in the manage displays page. Uninstalling the module, brought them back. This is using D 8.5.3 and the 8.x-1.1 version of this module.

calebyoder’s picture

Was having issues getting Blazy, responsive images, and linked field working together. I applied patch #13 and it seems to be working so far.
Thanks!

PaulDinelle’s picture

In case anyone is interested, I've created a generic fix for this issue (and similar elements). It allows you to specify which elements you want to wrap with an anchor and prevents recursion on those chosen elements, which is mostly what the patch here does but without the configuration options.

We needed this for the FontAwesome field module, but I see it could be useful here as well.

https://www.drupal.org/project/linked_field/issues/3088623

edwardchiapet’s picture

We were having issues where images were duplicated with the Image Lazyloader module, and patch #13 seems to have resolved that for us!

JFKiwad’s picture

The patch (#13) still works (Tested on Drupal v9.2.8)

mighty_webber’s picture

StatusFileSize
new1 KB

#13 did NOT work for me. (9.4). This patch works on the front end, but does not pre-populate layout builders with the previously selected/saved value.

heddn’s picture

Status: Needs review » Closed (duplicate)

This issue, while older, is behind the work over in #3197132: Linking breaks responsive image formats. Closing duplicate to it.