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.
theme_image_formatter() is a wrapper around theme_image_style() and theme_image(), both of which allow attributes to be added to the <img> tag.
Attributes can be already be added to the link if it exists, via $variables['path']['options']
.
Comment | File | Size | Author |
---|---|---|---|
#22 | image-attributes.patch | 1.87 KB | RobLoach |
#17 | image-attributes-testonly.patch | 951 bytes | jthorson |
#14 | image-attributes.patch | 1.87 KB | RobLoach |
#10 | drupal-1329586-10.patch | 510 bytes | tim.plunkett |
#5 | drupal-1329586-1.patch | 1.24 KB | RobLoach |
Comments
Comment #1
tim.plunkettAttached both D7 and D8. Yay for cherry-pick.
Comment #2
tim.plunkettWhoops, dupe of #1025796: Rename path to uri in image functions
Comment #3
tim.plunkettReopening to get this in first, then rename path to uri.
Comment #4
RobLoachWould be nice if we just used straght up
$variables
there instead of having to switch over to$image
for Drupal 8. Save us a couple lines of code. For Drupal 7 though, it looks fine.Comment #5
RobLoach#1025796: Rename path to uri in image functions was committed, so this might not be needed for Drupal 8. For Drupal 7 though? Bot?
Comment #7
tim.plunkett#5: drupal-1329586-1.patch queued for re-testing.
Comment #8
jthorson CreditAttribution: jthorson commentedI'm thinking we should be checking $item['attributes'] as well as $variable['attributes'] ... if I'm working with upstream code that sets a 'title', 'alt', and 'fid' attribute on an image and then returns that image, these all get tacked on to $item.
If I want it to appear in $variables['#attributes'] for proper rendering with this patch, I would then have to pull the 'fid' out of $item and plug it into $variables['#attributes'] later in the pre-process function. This feels hackish to me.
That said, I can also see the benefit of being able to tack on '#attributes' when defining the render array.
How about something like this?
Comment #9
RobLoachWhat if it were to JUST check
$item['attributes']
? Looking at theme_image_formatter(), we see "item: An array of image data."..... Then looking at theme_image(), we see that the image data is along side the "attributes".....Actually, I agree that we probably don't want to override it if it already exists... hmm.
Comment #10
tim.plunkettIt makes it a little clearer that the attributes are for the image, not for the possible link.
But it makes it harder to document.
Comment #11
RobLoach#10: drupal-1329586-10.patch queued for re-testing.
Comment #12
ultimateboy CreditAttribution: ultimateboy commented#10 works great. I think it's time to RTBC.
Comment #13
webchick1. We need some documentation of that newly accepted parameter.
2. Let's also add a test for this.
Comment #14
RobLoachIt's technically not a new parameter, as it was expected in theme_image(), but absolutely ignored in theme_image_formatter(). I'm with you that more documentation never hurts though!
Explicit test added!
Comment #16
ultimateboy CreditAttribution: ultimateboy commentedComment #17
jthorson CreditAttribution: jthorson commentedAnd just for the sake of completeness ...
Comment #19
jthorson CreditAttribution: jthorson commentedComment #20
ultimateboy CreditAttribution: ultimateboy commented#17: image-attributes-testonly.patch queued for re-testing.
Comment #21
RobLoachThe patch is missing the $item['attributes'] updates from #14.
Comment #22
RobLoachre-upped.
Comment #23
ultimateboy CreditAttribution: ultimateboy commentedAlright.. this is definitely ready to go.. good documentation, a test which has been shown to fail in #17 and a fully functional test-passing patch in #22.
Comment #24
jthorson CreditAttribution: jthorson commentedRobLoach: That was intentional. (ie. test-only). ;)
Comment #25
xjmHmm, can someone confirm that it's not needed in D8 (as per #5)?
Comment #26
RobLoachCorrect, Drupal 8 got the more elegant solution over at #1025796: Rename path to uri in image functions, and has been in since November. Drupal 7 just gets this simple
$item['attributes']
check. I posted the difference between the branched patches right here.Ah, proof that this patch is needed :-) .
Comment #27
webchickCool, that looks great!
Committed and pushed to 7.x. Yay!
Comment #29
ñull CreditAttribution: ñull commentedDoes this patch also include the title attribute? I have the title attribute set but I don't see it in the output.
Comment #30
ñull CreditAttribution: ñull commentedComment #31
ñull CreditAttribution: ñull commentedFalse alarm. It was a JS issue.