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.
From http://drupal.org/node/1553094#comment-6746236, now we can have alt/title in 'Rendered File' display format (Thanks a lot :)). But when it is changed to other format like 'Image', 'ShadowBox', there will be empty alt tag and no title. I think it is also essential to have this feature. It would be great to have it working for all display format.
I tried the code from http://drupal.org/node/1553094#comment-6704686 without success.
Thank you.
Comments
Comment #1
ParisLiakos CreditAttribution: ParisLiakos commentedComment #2
peximo CreditAttribution: peximo commentedHi, I use this hook to show the alt and title also in colorbox etc.
I don't know if this is the right approach but it works.
Comment #3
supradhan CreditAttribution: supradhan commentedpeximo: Thank you. I will try this.
Comment #4
supradhan CreditAttribution: supradhan commentedpeximo:
I used the code you provided in my theme template.php for shadowbox but it didn't work. Am I missing anything?
Comment #5
peximo CreditAttribution: peximo commentedYou must resave the content; also is the function correctly called? I use this code in a module, I don't know if you can do this in a theme.
Comment #6
HyperGlide CreditAttribution: HyperGlide commented@peximo can i suggest you sandbox your module. Perhaps that can help with the initial issue of supporting other display modes.
Comment #7
vgutekunst CreditAttribution: vgutekunst commentedHi,
i which file i have to add this code? I need the alt & title in colorbox too! Plz help me!
regards
Comment #8
peximo CreditAttribution: peximo commented@HyperGlide: You mean a module for this hook? If this is the right approach I think is better a patch.
@lolhonk: you should create a module (eg: media_misc) and implement this hook (eg:
media_misc_field_attach_presave()
)Comment #9
supradhan CreditAttribution: supradhan commented@Peximo: Thank you a lot. Now it is working in the shadowbox and I managed to use theme_image_formatter for other displays.
Is it possible to use theme function for shadowbox case also so that I can move the hook function from shadowbox module to theme template?
Thanks
Comment #10
HyperGlide CreditAttribution: HyperGlide commented@peximo my reference was only as a work around, not a long term solution. A patch is much better!
Comment #11
vgutekunst CreditAttribution: vgutekunst commentedThe code doesnt work. I put them in a mymodulename.modul and activated this modul but the alt and title field appears only when i choose "rendered file"
Comment #12
supradhan CreditAttribution: supradhan commented@lolhonk: You need to edit and re-save the content to make it work. Also make sure your hook function declaration is mymodulename_field_attach_presave($entity_type, $entity). If it still not working then try to debug and see if your code is being called or not.
Comment #13
moniuch CreditAttribution: moniuch commented@peximo Thanks for the code, it definitely works. I have been trying other hooks so to workaround having to resave the content, but none of them worked. Have you tried them too? hook_field_prepare_view, hook_field_formatter_prepare_view, hook_field_load - the first being the most appropriate, bot actually none of them was triggered as a dummy dpm was not firing.
Comment #14
Devin Carlson CreditAttribution: Devin Carlson commentedThis will be fixed by #1496942: Support making any kind of meta-data available to file_load() and file_load_multiple() consumers.
Marking this as a duplicate since I don't think that there's any other "proper" way to do this in the interim.