A number of problems come from the fact that core image fields store alt and title data with the field and not with the file entity itself. Now that we have an API for storing file metadata #1496942: Support making any kind of meta-data available to file_load() and file_load_multiple() consumers, we have a way to store alt and title information with the file itself.
This will allow us to remove all of the field-based alt + title solution committed as part of #1307054: Accessibility - Media browser image alt and title fields and fix/improve:
- #2012868: A better description for the alt and title attributes of images
- #1887714: Enforce non-empty alt / title attributes + consistency for empty title attributes with core.
- #1987568: Alt and Title Text "
- #2017647: Media browser translatable alt and title fields for translatable parent entity
- #1343022: Adding alt and title attributes from fields to image markup
- #1672944: Edit alt and title fields of images in media content form
- #1941136: Getting Alt and Title attributes to appear in IMG element
- #1392900: Integrate File Entity Link's features into File Entity?
This would also allow us to remove the confusing "duplicate" image file formatter, allow linking images to their parent entities out of the box (something the "fake" image file formatter doesn't do) and provide an easy way for other contrib modules to work with image alt and title tags, ie:
if (module_exists('file_entity')) {
$alt = check_plain($file->metadata['alt']);
$title = check_plain($file->metadata['title']);
}
Comments
Comment #1
Devin Carlson CreditAttribution: Devin Carlson commentedA patch to convert alt and title information from field information to file metadata when saving an entity and convert alt and title information from file metadata to field information when loading an entity.
It also alters the default image formatter provided by the core image module to load alt and title information from file metadata instead of from field information.
Finally, it adds the ability to modify alt and title information when editing files and removes the field-based alt + title code committed as part of #1307054: Accessibility - Media browser image alt and title fields.
@todo is an upgrade path from field-based alt + title and hooking this into the file upload wizard.
Comment #2
Devin Carlson CreditAttribution: Devin Carlson commentedAn updated patch which adds another step to the file upload wizard for adding metadata and an update function for migrating field-based alt and title text to metadata.
Comment #4
Devin Carlson CreditAttribution: Devin Carlson commented#2 was missing a few changes from #1.
Comment #5
Devin Carlson CreditAttribution: Devin Carlson commentedComment #7
Devin Carlson CreditAttribution: Devin Carlson commentedAccommodated additional file upload wizard step in tests.
Comment #8
Devin Carlson CreditAttribution: Devin Carlson commentedI'd expect that many/most of the existing sites using File entity utilize the file_image formatter so removing it would cause major backwards compatability problems.
The attached patch adds a hidden module whose sole purpose is to provide the file_image formatter for backwards compatibility reasons. The module is enabled for existing sites that utilize the alt or title fields and remains hidden for new installations of File entity.
While one or two follow up issues may be uncovered (i18n integration and easy upload wizard alterability are obvious ones but not directly caused by this issue), I think that this is ready to go and will commit in the next few days unless anyone has any objects/concerns/improvements. :)
Comment #9
Devin Carlson CreditAttribution: Devin Carlson commentedInstead of altering alt and title text into the image formatter it is probably best to just add alt and title information directly to files (in addition to being available in the array of file metadata) when they are loaded as the core image module does.
This should make alt and title text work seamlessly with any of the contrib modules out there. I tested this with the Colorbox module without any issue (this would also make the Media Colorbox module obsolete).
Comment #10
aaron CreditAttribution: aaron commentedFirst, I am not certain if the way that you've implemented hiding the file_entity_image_formatter module is the best way; if an administrator accidentally disables the module there's no way to re-enable it.
Secondly, this patch will sadly break the ability to override the alt/title attributes from the WYSIWYG #835516: Add ability to edit file meta data and fields when embedded in WYSIWYG. Although please don't let that hold up things, as we can create a follow-up issue for the media module.
Comment #11
Devin Carlson CreditAttribution: Devin Carlson commentedMarked #1941136: Getting Alt and Title attributes to appear in IMG element as a duplicate.
Comment #12
Dave ReidI believe we solved this with #2061531: Double 'Image' file formatter in the 'Manage file display' tab, so I'm going to close this out. If there is still a remaining task here, please re-open.
Comment #13
thursday_bw CreditAttribution: thursday_bw at Catalyst IT commentedUnfortunately this is still an issue.
I just
* installed and enabled file_entity on a fresh drupal install.
* Added an image field to the Basic Story type.
* Allowed alt and title text on the new image field.
* Created a new 'basic story' node, and uploaded an image on that node form.
* Filled in the alt and title subfields of the image field.
* Viewed the newly created file entity.
The title and alt fields are empty.
Unfortunately the patch on #9 on this issue is so old that the code has diverged significantly and this patch not longer applies cleanly.
Comment #14
thursday_bw CreditAttribution: thursday_bw at Catalyst IT commentedComment #15
steinmb CreditAttribution: steinmb as a volunteer commented