Problem/Motivation

File Entity Alt & Title text fields are both set to a maximum of 255 characters whereas core (D7 & D8) image Alt & Title text fields are set to 512 & 1024 respectively. These sizes limit the input to both these fields (e.g. using the media module's media browser) and we have had several requests from clients to increase the length supported for both alt and title fields.

Proposed resolution

The install should be updated to increase the sizes of the alt & title fields when they are created and provide an update to increase the size of the fields in existing installations

The original issue that discusses this update to core - #1353030: Increase length of "alt" and "title" text for images
There is a lot of discussion about closer integration with the Alt & Title fields used by File entity and those used by core #2070183: Sync alt and title text between file entity and standard image field & how best to handle alt & Title attributes generally #2029985: Store core image field alt and title text using the File Metadata API

There is some interesting discussion about the size limit used for varchar() fields proposing that text fields above 255 should become text type fields (see #63 in #1353030: Increase length of "alt" and "title" text for images) - This issue/discussion only deals with making the fields the same size as their core equivalents.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

iAugur’s picture

I have attached a patch that updates the field specs for the Alt & Title fields and provides an update function to update existing installations.

Dave Reid’s picture

Status: Active » Needs work

The updates could be a lot simpler just by using field_read_field() and modifying the field setting that needs to be changed, rather than re-definining the entire field, which may overwrite anything the user has changed. Will making this change without changing the field type actually work?

iAugur’s picture

Good point, thanks Dave. I have updated the patch as you recommend to only change the field sizes if they are the same as the previous defaults.
We don't have to change the field type as > 255 is OK for varchar fields (it may be better to use text type fields but the motivation was to keep in sync with core).

iAugur’s picture

I have updated this again as we can't change the schema when data already exists. So it now checks for data before trying. If we run field_update_field when data already exist we will get FieldUpdateForbiddenException.
Do you know if it is possible to avoid this?
We could run db_change_field() to change the database directly but then field_config is out of sync.

guy_schneerson’s picture

If field_config is out of sync then code like the Media module will pick up the wrong size and although the storage will be correct it will not be used.
It would be good to get this sorted - how did the core image updated achieve this?