There have been some issues with the TITLE and ALT attributes missing which have been fixed with a patch to the core file module.
See https://drupal.org/node/2065507#comment-7760101
I believe there are still some inconsistencies with the TITLE and ALT tags. I'm putting this as a bug as I consider it one, but this could be down to my understanding of how it all fits together.
The problem (as I see it).
The Title and ALT tags are not syncing properly between the conventional image field and the newer file entity.
If I have a content type field set to the conventional image field and update the ALT and TITLE attributes and save the node, this is not reflected when I go to content -> files and edit that entity.
The same if I edit the entity via content -> files and update the attributes there and save. This is not reflected when I go to the node edit form.
Therefore it seems to be keeping two copies of the ALT and TITLE attributes rather than them being synced. This doesn't seem right as if I delete the image via content -> files the image is no longer present when I edit the node, which I would expect to happen as it's referring to the same image.
Also to note,
If I edit the ALT and TITLE attributes save the node, then go to content type and change the field to media file selector and edit the node again, the changes cannot be seen in the new image view.
However, the reverse it does synch. If I edit the ALT and TITLE tags, save the node, go back to content type and change it back to the conventional image type and view the node once again the ALT and TITLE tags reflect the changes I did.
Forgive any incorrect use of the terminologies, however, while the two methods of creating an image field still exist, I would expect them to be sync'd.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | file_entity-sync-alt-title-text-2070183-14.patch | 3.25 KB | joegl |
| #2 | display-settings.JPG | 31.84 KB | OriginalSauce |
Comments
Comment #1
devin carlson commentedTake a look at #2029985: Store core image field alt and title text using the File Metadata API which implemented the solution that you're suggesting.
Comment #2
OriginalSauce commentedHi Devin,
Thanks for quick reply. I did come across this post when I was looking for solution to the missing alt and title fields. I have both the latest dev releases for file entity and media.
Just looking at the patch in #9. Is it ok to patch this in with the latest dev release?
At the time I didn't think this applied to my issues as I was not having a duplicate formatter problem.
See attached image. Will this patch make the title and alt tag appear in the display settings, which I don't currently see?
Thanks for your patience.
Comment #3
OriginalSauce commentedWhether it does or not, I've decided to not implement any patches that aren't committed. Doesn't make sense to apply a patch on a module with regular updates.
Not that this is a bad thing of course.
Comment #4
mindgame commentedAs long as we have duplicate alt and title text data they should at least be synchronized.
Why only doing that for the image dimensions?
See _file_entity_update_image_field_dimensions():
We could just add the image captions to make the set of four image attributes complete:
where
and replacing the weird condition
by one that is more likely to be satisfied.
Now, when updating a file entity the image captions of the image fields will be updated as well.
This solution differs from Devin's proposal above to use the File Metadata API for alt and title text.
Comment #5
mindgame commentedNow the opposite direction.
Updating the file entity after changing the captions of image fields, for example when saving a node.
Inspired by file_entity_field_attach_load().
Comment #6
spadxiii commentedIf you allow empty alt/title tags, this is still giving a problem. Empty alt/title will be saved as NULL in the core field-tables. Because of the a core patch (which reverses arguments in array_merge: https://drupal.org/node/2066275#comment-7759503) this results in the file entity having alt/title of NULL. This in turn removes them from the output in theme_image (isset gives a FALSE for NULL values)
In
file_entity_field_attach_load()the alt/title tags are loaded from the file-entity but they're not overwritten if you leave the fields empty:if (empty($item[$key]) && !empty($file->{$key})) { .. }Overwriting these fields in case the field has NULL-values works by changing that if statement to:
if (is_null($item[$key]) || !empty($file->{$key})) { .. }Comment #7
askibinski commentedWell, I used 2 hooks to sync alt/title tags between core image field and file entities. This seems to work nicely as long as alt/title tags are required.
The second one is inspired by mindgame's comment above, but adapted so the file entity fields will only be overwritten when empty.
Also, the code should be language aware (alltough that needs more testing).
Comment #8
gmaximus commentedThanks askibinski ... Your code worked like a charm, I thought it was just me doing something wrong.
Comment #9
yfma commentedI am having the same issue as SpadXIII described. The alt and title text were added to file entity itself with empty string (decorative image). When you are using the media widget on image field with this image, The field_image_alt and field_image_title columns are both NULL in field database tables. So the alt and title got removed from the image field output, the screen reader will always think that the image is present and will read the filename instead.
SpadXIII's code is working great. should we have a patch for it?
Comment #10
IckZ commentedThanks so much for the code! Works like a charm!
Comment #11
rodrigoaguileraI just tested the hooks in #7 and they work nicely. Now I can show the img title as displayed text in the view mode :)
I wonder why don't we try to get this into the module. Maybe making the sync always is not the desired outcome so we can alter the image widget config to have a checkbox that reads something like "have the title and alt fields in sync with the file entity fields" and perform the sync only when this option is checked.
The patch seems pretty simple.
What do you think?
Comment #12
mercepedraza commentedI also added the code in #7 to hook_field_attach_insert() to get the change when the node is created, otherwise I needed to edit and save the node after having created it to see the img title displaying.
Comment #13
nelslynn commentedAny help tweaking #7 to work with images in a product entity (Drupal Commerce)?
Comment #14
joegl commentedI added both hooks from #7 to the bottom of the file_entity.module and confirmed they are working. I then pushed both hooks into a patch for the 7.x-2.x branch. I imagine these changes could be better implemented into the core of the module, instead of using hooks. However, I am unfamiliar with this module and wouldn't know where to start!
Mindgame is probably on to something with creating similar functionality to the _file_entity_update_image_field_dimensions() function in file_entity.file.inc. Also possibly putting code directly into the file_entity_field_update function might be ideal.
Comment #15
joseph.olstadare you sure this is still needed with the newest release (7.x-2.6) ?
have a look at this recently fixed issue:
#2806081: translated Title and Alt text fix, use optionally with entitycache and entity_translation
Comment #16
joegl commentedI had looked at that issue and applied the patch with no effect previously. I will try it again soon, thanks!
Comment #17
joseph.olstadI had a quick look at the patch #2070183-14: Sync alt and title text between file entity and standard image field
looks ok, I think it should go into 7.x-3.x first.
RTBC for 7.x-3.x , but needs review for 7.x-2.x
Comment #19
joseph.olstadThis is now in the 7.x-3.x branch
to try it, use 7.x-3.x-dev
Comment #20
joseph.olstadneeds review for 7.x-2.x
Comment #21
joseph.olstadComment #22
joseph.olstadComment #23
joseph.olstadThis isn't working for my use case (image style applied to a file_entity in a view)
my working solution is a core patch:
#2835135-1: image formatter needs to handle alt/title from file entities on images for multi language support
Comment #24
joseph.olstadI believe this is completely fixed by the recent david_rothstein fix in a possibly related/duplicate issue.
#2665960: Image Alt and Title displayed in the wrong language IF field format is not "rendered file"
If confirmed as fixed, I will back off the commit that was previously made to 7.x-3.x