Media items created via the media library widget should have the same langcode as their parent entity

Created on 30 May 2024, 5 months ago

Problem/Motivation

In a multilingual site, when creating media items via the media library widget, the created media items do not always have the same langcode as the parent entity through which they are created. The media library widget simply creates a media item without specifying a langcode, which makes the langcode default to the sites default langcode.

Since users add an alt text in the language of the parent content, this can be problematic.

Steps to reproduce

  1. Setup a multilingual site.
  2. Add a media field to a content type with the media library widget.
  3. Create a translation for existing content, or new content in a non-default language.
  4. Add a media item to the content using the media library widget.
  5. Observe that the created media item has the default langcode, instead of the langcode of the content through which it was created.

Proposed resolution

Pass the langcode of the parent entity to the media library, and use it to create new media items.

Remaining tasks

Write patch
Add tests
Review
Commit

User interface changes

None

API changes

A new optional langcode parameter is added to AddFormBase::createMediaFromValue. It is a protected method, but media library add forms extending the class might need to be updated.

Data model changes

None

Release notes snippet

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
MediaΒ  β†’

Last updated about 7 hours ago

Created by

πŸ‡³πŸ‡±Netherlands seanB Netherlands

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024