Check max length of media image alt text

Created on 29 April 2025, 3 months ago

Problem/Motivation

Getting following error on saving translation of media image alt text which exceeds the database max length.
Drupal\Core\Entity\EntityStorageException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'thumbnail__alt' at row 4: INSERT INTO "media_field_data" ("mid", "vid", "bundle", "langcode", "status", "uid", "name", "thumbnail__target_id", "thumbnail__alt", "thumbnail__title", "thumbnail__width", "thumbnail__height", "created", "changed", "default_langcode", "revision_translation_affected", "content_translation_source", "content_translation_outdated", "publish_on", "unpublish_on", "publish_state", "unpublish_state")

Steps to reproduce

Add a media field with Image type with alt enabled.
Create a page.
Translate using tmgmt.
Add text into alt field in translation more than 512 characters.

Proposed resolution

Validate the max length before submitting.

Remaining tasks

Review.

Feature request
Status

Active

Version

1.0

Component

Miscellaneous

Created by

🇮🇳India sakthi_dev

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @sakthi_dev
  • Pipeline finished with Failed
    3 months ago
    Total: 376s
    #484557
  • 🇯🇵Japan dc-kinoshita

    We are facing the same problem with alt text in all images.
    Setting a validation is good idea, but preventing such cases is good too.
    In general, maxwidth attribute is being send to notify about length restrictions, but I believe that in case of alt text the data structure is different.
    It leads to the behavior when the maxwidth is not being sent in the xliff.

    If possible, it might be a good idea to modify the source code so it would send maxwidth for alt text too.

Production build 0.71.5 2024