Problem/Motivation
When inserting an asset from Acquia DAM into a Drupal node using the "Add or select media" modal, the operation fails with a SQLSTATE[22001]: String data, right truncated error if the asset's alt text exceeds the maximum length supported by the acquia_dam_managed_image_alt database column (varchar(512)).
This happens because assets in DAM can have very long alt text values (e.g., keyword-rich metadata strings), and the current string field type with max_length: 512 imposes a hard database-level ceiling that DAM-sourced alt text can easily exceed.
Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'acquia_dam_managed_image_alt' at row 1: INSERT INTO "media__acquia_dam_managed_image" ("entity_id", "revision_id", "bundle", "delta", "langcode", "acquia_dam_managed_image_target_id", "acquia_dam_managed_image_alt", "acquia_dam_managed_image_title", "acquia_dam_managed_image_width", "acquia_dam_managed_image_height") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->saveToDedicatedTables() (line 1400 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
Steps to reproduce
- Install the
acquia_dammodule (version 1.1.15) on Drupal. - Configure the integration with an Acquia DAM account containing assets whose alt text field holds a string longer than 512 characters.
- Create or edit a node and insert such an asset via the Acquia DAM media selector.
- Observe the
SQLSTATE[22001]SQL error triggered when attempting to save the media entity.
Proposed resolution
Change acquia_dam_alt_text from a string field (hard-capped at max_length: 512) to a string_long field (unbounded TEXT column). This removes the DB-level length ceiling that DAM-sourced alt text can exceed.
Code change — ImageAltTextField::bundleFieldDefinition():
private static function bundleFieldDefinition(): BundleFieldDefinition { return BundleFieldDefinition::create('string_long') ->setProvider('acquia_dam') ->setName(self::IMAGE_ALT_TEXT_FIELD_NAME) ->setLabel(new TranslatableMarkup('Alt text')); }
(max_length setting is dropped, as string_long doesn't support it — the column becomes TEXT.)
Migration for existing sites via hook_update_N():
- Directly alter the underlying database column(s) for
acquia_dam_alt_textfromvarchar(512)toTEXTvia the schema API ($connection->schema()->changeField()), covering both the dedicated field table and the revision table. - Update Drupal's stored field storage definition record so it matches the new
string_longdefinition and futuredrush entity:updatesruns don't report a mismatch.
Because varchar → TEXT is a widening, compatible conversion, existing alt text data is preserved with no truncation or loss.
Issue fork acquia_dam-3611070
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
rajeshreeputraComment #4
rajeshreeputraRequesting review.
Comment #6
rajeshreeputraMR merged!