Hi. I’m developing a plugin to customize what metadata is used to generate the alt-text for images on Omeka in order to enhance Omeka’s accessibility. With the file_markup filter, it was simple to take the $html, replace the alt-text section of the string, and return it with the changes. However, the changes are only effective on file/show pages because that is the only place file_markup() is called.
The function item_image is used to generate the alt text for almost all image items. It calls image_tag() directly in FileMarkup.php instead of calling the file_markup() function, so the changes made to the $html my file_markup filter are bypassed.
Are there any methods to use a filter to modify the html code returned by image_tag() in FileMarkup.php, any suggestions to modifying the data image_tag() returns through a plugin, or any other approaches I could take to customize the alt-text for images?
Unfortunately, there really isn’t a way to get at the “simple” image output from image_tag… as a somewhat internal part of the fileMarkup helper it doesn’t have extension points of its own, and since it’s referenced directly by the functions that are using it in this way, you can’t even use the Zend Framework system that would let you replace the helper itself with a different implementation.
We can look to add a hook or filter directly there in the future, but that wouldn’t help you now. Are you focused on the admin or public side? (Or both, perhaps.) The public side is easier to deal with since themes can just directly pass the desired alt attribute into the function rendering the image tag.
Thank you for taking the time to respond to my question as I’m fairly new to Omeka and have just started working with plugin development.
Using themes to directly pass the alt attribute into the function rendering the image tag sounds like it could work for the most part. However, I’m hoping to develop a theme-independent solution that works both on the admin and public side for images. I’m also developing a form for the admin side that lets users customize what metadata is used for the alt-text.
Since there’s not a straightforward way to filter image_tag, do you have any ideas of other approaches to this problem?
Thanks again for your help!
The only way I can think of at the moment to get this to work without theme changes is to make changes to the core to allow that. This also means you’d have to wait for a future release for the plugin to work, of course. A filter for attributes right in image_tag is probably the simplest option, but if you’ve got a different proposal I’d be glad to hear it.
Hi @jflatnes. Sorry to revive an old thread, but we are still interested in being able to filter alt text across all thumbnails, and haven’t been able to figure out a different proposal to do it without modifying theme files. Would you all still be open to considering a filter for attributes in image_tag() in a future core update? Should we file an issue on the repo?
Sure, I still think it’s a good idea. Go ahead and file an issue. (Of course, feel free to do so without my say-so too)
I’m told there is a workaround to edit the public theme to display alt text for items, drawing from (for example) the Description property for that file’s metadata. How might we accomplish this?
item_image (and all the various equivalent functions for displaying images from records) take an argument generally called
$props that’s just an array of attributes… setting
alt or anything else here will cause it to be output as part of the tag.
For example, outputting a thumbnail of the “current” item with its description as the
alt attribute could look like:
$description = metadata('item', array('Dublin Core', 'Description'), array('no_escape' => true));
echo item_image(null, array('alt' => $description));
It would largely be an exercise in finding places where you’re looking to make that change and doing a replacement. If it’s in several places you could do a simple function in the theme to avoid needless repetition.
That example used an Item, but a File could be used as the metadata source and/or the record being output just as easily. The default
alt code will already read the Title element of a File.
Oh and I’ve just now added the filter discussed earlier in this thread, at least in its initial form.
I can’t say with certainty when a release would come that includes the new filter, but it would likely be Omeka version 2.7, which would be the next release.