Uncheck "Overwrite original file" does not overwrite the Media's name

Created on 28 November 2022, over 1 year ago
Updated 17 May 2023, about 1 year ago

Problem/Motivation

The field 'Name' of Media entity does not change its value after an existing entity got saved (new source file with option "Overwrite original file" unchecked), but preserves its old value (the old file's name) instead. This could be an issue if there is a Media listing page (Views module) with filtration by Name. It will work for the newly added media as the column 'name' within 'media_field_data' table would be exactly the same as 'filename' within 'file_managed' table, but it fails as soon as an entity changes its source file (option "Overwrite original file" unchecked). In this case, only the column 'filename' within 'file_managed' table will be changed.

Steps to reproduce

1. Add new Media item (for example: new file 'test.txt').
2. Check the database tables 'media_field_data' (column 'name') and 'file_managed' (column 'filename') - must have the same filename.
3. Edit the Media from step 1 and change the file. Do not check the option "Overwrite original file".
4. Check again as on step 2 - 'file_managed' (column 'filename') has the new filename, but 'media_field_data' (column 'name') hasn't.

Proposed resolution

Could use \Drupal\media\Entity\Media::setName()

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡§πŸ‡¬Bulgaria rkostov

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024