Problem/Motivation
ImageCaptionItem::schema() unconditionally adds caption and caption_format columns to the storage table of every image field, regardless of whether that field instance actually has captions enabled (caption_field setting). Because these columns are named literally {field_name}_caption / {field_name}_caption_format — with no module-specific namespacing — they can collide with an entirely unrelated field on the same bundle if that field happens to be named {image_field_name}_caption.
Steps to reproduce
- Create an image field, e.g. field_photo.
- Create a separate, unrelated formatted text field (e.g. text_with_summary) named field_photo_caption on the same content type.
- Install/enable image_field_caption (captions do not need to be enabled on field_photo for this to occur).
- Populate field_photo_caption with a value and a non-default text format (e.g. Full HTML).
- Load the entity via the Entity API (or view it on a page) and inspect $entity->get('field_photo_caption')->first()->format.
Expected: the stored format (e.g. full_html) is returned.
Actual: the format is empty/blank. Drupal's generated SQL query joins both the image field's table and the text field's table into a single SELECT, and because both tables independently produce a column aliased field_photo_caption_format, the (empty) value from the image field's unused caption subfield silently overwrites the real value from the text field. Any rendering that relies on the stored format (e.g. check_markup() via the text_default formatter, or a Views field) then falls back to the site's fallback format, which HTML-escapes the content and can visibly break the display — raw markup shows up as literal escaped text instead of rendering.
Impact: silent, hard-to-diagnose data corruption at read time (nothing is actually wrong in the database — field_photo_caption_format is stored correctly; it's only mis-read on load). This will affect any site where a content type happens to have both an image field X and a separate formatted-text field named X_caption.
Proposed resolution
namespace the schema columns added by ImageCaptionItem::schema() so they can't collide with genuine field names — e.g. prefix with something module-specific like ifc_caption / ifc_caption_format instead of the bare caption / caption_format. This would need a schema update hook to migrate existing installs' column names.
Comments