Problem/Motivation
Follow up issue for #2829990: Image formatter does not support URL/Link options
When using a responsive image field formatter and adding a link to a file or hosting entity, URL options are not handled by the native image formatter so it is impossible to add a class or other attributes to the generated link...
function : template_preprocess_responsive_image_formatter
template : responsive-image-formatter.html.twig
Proposed resolution
Use the link() Twig method to render the linked responsive image, so URL options are output as expected.
Remaining tasks
- Review
- Commit
User interface changes
None.
API changes
Linked responsive images can now render link attributes.
Data model changes
None.
| Comment | File | Size | Author |
|---|
Issue fork drupal-3064751
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:
- 3064751-responsive-image-formatter
changes, plain diff MR !14965
Comments
Comment #2
krzysztof domańskiComment #4
idebr commentedChange looks good! However, the change to the template should also be applied to the template in
core/themes/stable/templates/field/responsive-image-formatter.html.twigComment #5
krzysztof domańskiComment #8
ocastle commentedI can also confirm that the patch works well for me.
Just a case of fixing the failing tests.
Comment #9
idebr commentedtemplate_preprocess_responsive_image_formatter()documents$variables['url']asAn optional \Drupal\Core\Url object. However, the code path for 'Linked to file' currently returns a relative path ('/sites/simpletest/...') instead of an Url object. I have updated the code accordingly.Comment #11
lendudePatch looks good, nice test coverage and fix is in line with the fix in #2829990: Image formatter does not support URL/Link options
Comment #12
lendudeComment #14
xjmThe 9.1.x test failed with:
Comment #15
ravi.shankar commentedHere I have added a patch that might pass failed tests.
Comment #17
ravi.shankar commentedThis patch might pass the tests.
Comment #18
ravi.shankar commentedThere was an issue in the patch #17, so added a new patch for review.
Comment #19
idebr commented#14 The test failures in 9.1.x have been addressed.
Setting back to RTBC.
Comment #20
alexpottWhy are we mixing this change with a change to whether this is absolute or not. That doesn't seem something that should occur without discussion and doesn't seem to be in-scope.
Also as we're changing the type of a theme variable from a string to a Url object we should have a change record.
Comment #24
ocastle commentedRe-rolled patch #18 for 9.3.x
Comment #26
idebr commented#20.1 The URL is now relative again, so this is unchanged compared to HEAD
#20.2 Change record is available at https://www.drupal.org/node/3291487
Comment #29
dydave commentedThe failure of tests for patch 3064751-26-test-only.patch from #26 above, demonstrate the tests are working and the patch fixes the isse:
Setting back to Needs review.
Thanks in advance!
Comment #31
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #need-reveiw-queue. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge require as a guide.
IS proposed solution appears to match what is being accomplished in the patch. - Good
Tests only patch is showing red/green - Good
At this time we will need a D10.1.x version of the patch. (Should be close but instead of stable it's stable9 now)
Also the CR think could use an update to mention the change being done to the twig templates. If themers have their own responsive-image-formatter.html.twig they will have to update to work correct.
Comment #32
ravi.shankar commentedAdded reroll of patch #26 on Drupal 10.1.x. keeping the status to needs work for other things of comment #31.
Comment #36
idebr commentedComment #37
smustgrave commentedSmall comments, but super close!
Comment #38
idebr commentedComment #39
smustgrave commentedI meant we could drop the @var since it’s typed. Sorry
Comment #40
idebr commentedThe
@vardeclarations are now removed from the typed properties:Comment #41
smustgrave commentedThanks sorry I wasn’t clear the first time. Feedback appears to be addressed nothing else to add
Comment #43
godotislateI made a couple minor changes to the MR:
In ResponsiveImageFormatter.
$fileUrlGeneratorconstructor parameter. This is to avoid making the property itself nullable.In ResponsiveImageFormatterTest:
mb_strolowerwrapping of$this->randomMachineName(), since the generated random machine name is already all lower.If someone could give this a +1 for RTBC, I can commit.
Comment #44
idebr commentedThanks @godotislate, the changes look good to me!
Comment #48
godotislateCommitted and and pushed a85f1db to main and 458eb45 to 11.x. Thanks!
I forgot to mention I made some small edits to the CR the last time I reviewed. I have published the CR now as well.