Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Using the "Link image to" feature of the picture formatter causes a fatal error:
Fatal error: Cannot use object of type Drupal\Core\Url as array in /core/modules/responsive_image/src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php on line 129
Steps to reproduce:
- Set up a responsive image mapping
- Create a content type with an image field
- Set the default display mode to use the responsive image formatter and set the "Link image to" to "Content"
- Create a node
- View the node
- You see a WSOD with the error mentioned above
Proposed resolution
tbd
Remaining tasks
tbd
User interface changes
tbd
API changes
tbd
Original report by [username]
tbd
Comment | File | Size | Author |
---|---|---|---|
#10 | resp_image_link-2315077-9043095.patch | 2.97 KB | chrischinchilla |
#7 | resp_image_link-2315077-9042797.patch | 1.44 KB | chrischinchilla |
Comments
Comment #1
RainbowArrayUsing an image as a link is fairly common, so if that is causing a WSOD when Responsive Image module is being used, that's a pretty big problem. Bumping this to major. Will test to see if we can reproduce, and if so, start working on finding a solution.
Comment #2
chrischinchilla CreditAttribution: chrischinchilla commentedSeeing if I can reproduce…
Comment #3
chrischinchilla CreditAttribution: chrischinchilla commentedYup, did a fresh D8 install, followed steps above and get WSOD with -
10/08/2014 12:22:01.291 httpd[54712]: PHP Fatal error: Cannot use object of type Drupal\Core\Url as array in /Library/WebServer/Documents/drupal8/core/modules/responsive_image/src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php on line 129
Comment #4
chrischinchilla CreditAttribution: chrischinchilla commentedComment #5
chrischinchilla CreditAttribution: chrischinchilla commentedWill make some initial investigations to see what the issue is, might be beyond me, but you never know!
Here's a patch…
I'm not sure if I took the correct path, but I looked into 'ImageFormatter.php' and there was also viewElements function with very similar code. I replaced the erroring code with the code from there and things work.
After applying, make sure you clear cache and the responsive image with a link now works.
Comment #6
chrischinchilla CreditAttribution: chrischinchilla commentedComment #7
chrischinchilla CreditAttribution: chrischinchilla commentedComment #8
chrischinchilla CreditAttribution: chrischinchilla commentedDon't know what was up with that other patch, try this one!
Comment #9
RainbowArrayLooks good. Let's see what testbot says! Go testbot go!
Comment #10
chrischinchilla CreditAttribution: chrischinchilla commentedAs discussed with mdrummond he mentioned that a test would have spotted there had been a problem in the first place.
I have attached an attempt at a test, but I don't think it's completely correct and maybe doesn't really test anything.
Wasn't sure how to test multiple instances of a field or multiple fields and in fact, looking through other tests I don't think there are tests for fields linking to a content item anywhere, which may or may not be a problem. Or maybe this test isn't even needed, but here it is.
Comment #12
RainbowArrayLooks we have two issues tackling the same thing. Need to determine which has the best approach. This one has a start on tests, which is good.
Comment #13
RainbowArrayComment #14
attiks CreditAttribution: attiks commentedComment #15
swentel CreditAttribution: swentel commentedLet's mark this as duplicate in favor of #2254071: [PP-1] Responsive images can't be linked to Content - note, this is just done on the basis that the other one is older.