On several occasions we'd like to override the title for an image.

Currently theme_image_display hard codes this to the node title.

The attached patch checks to see if $attributes['title'] has been passed to the theme function, allowing the use of a custom title, rather than just the title of the node.

Comments

joachim’s picture

Status: Needs review » Needs work

I see the point of customizing the title, but I'm not sure I see the point of this patch.

How are you controlling what is passed to theme_image_display?
Surely if you're changing that, then you could equally override theme_image_display?

Also, what about ALT text?

blakehall’s picture

I agree it's not too tough to just override the theme function. The point is the default theme function should at least _allow_ passing in the title and alt via attributes rather than hard coding them.

With this patch you can call theme('image_display', $node, $label, $url, array('title' => 'My title', 'alt' => 'My alt text')

It would be trivial to add similar support for alt text.

Let me know if this explanation addresses your concerns. Thanks!

joachim’s picture

Sure, but what I'm wondering is -- where might you call that from?

blakehall’s picture

In our case, it's in a custom view handler.

We're displaying images that are attached to nodes related to the nodes that make up a view (if that makes sense). We want the alt and title text of the images to relate to the node relationship rather than the node that makes up the view. Without a custom handler you can only set the alt and title text of the anchor tag, rather than the actual image.

joachim’s picture

Ah right!
I couldn't see a case for this, but that makes sense.

The patch needs to deal with ALT along the same lines. If you have a second to make that change I'll commit it.

blakehall’s picture

Status: Needs work » Needs review
StatusFileSize
new836 bytes

This patch will allow both the alt and title text to be passed into theme_image_display via the attributes parameter.

Thanks!

joachim’s picture

Status: Needs review » Fixed

Great :)
Committed to HEAD.

Are you going to be at DrupalCon next week? I am trying to gather people together for a final code sprint to get image 1.0 released!
See http://paris2009.drupalcon.org/forum/image-10 for details.

blakehall’s picture

Unfortunately I won't be at DrupalCon Paris... I'm only able to make the spring events in North America.

I'll see if I can scrounge up some time to help with the sprint efforts though.

joachim’s picture

That would be a big help.
anything you can do in the next week basically -- lots of patches need testing :)

Status: Fixed » Closed (fixed)

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