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:

duplicate_image_formatter.png

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']);
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Devin Carlson’s picture

Assigned: Unassigned » Devin Carlson
Status: Active » Needs review
FileSize
17.41 KB

A 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.

Devin Carlson’s picture

An 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.

Status: Needs review » Needs work

The last submitted patch, store-alt-and-title-as-file-metadata-2029985-2.patch, failed testing.

Devin Carlson’s picture

#2 was missing a few changes from #1.

Devin Carlson’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, store-alt-and-title-as-file-metadata-2029985-4.patch, failed testing.

Devin Carlson’s picture

Status: Needs work » Needs review
FileSize
24.41 KB

Accommodated additional file upload wizard step in tests.

Devin Carlson’s picture

I'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. :)

Devin Carlson’s picture

Instead 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).

aaron’s picture

First, 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.

Devin Carlson’s picture

Dave Reid’s picture

Status: Needs review » Closed (duplicate)

I 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.

thursday_bw’s picture

Issue summary: View changes

Unfortunately 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.

thursday_bw’s picture

Status: Closed (duplicate) » Needs work
steinmb’s picture

Assigned: Devin Carlson » Unassigned
Priority: Major » Normal