Contents of Name field replaced by default value (i.e filename)

Created on 6 July 2020, over 4 years ago
Updated 11 June 2024, 6 months ago

Problem/Motivation

If a user enters a Name when saving a media-entity, that Name is correctly saved, overriding the default (i.e. the filename).

However, if they then edit the media-entity and re-upload the image, the Name is reset to the default (i.e. replaced with the filename).

Steps to reproduce

  1. Install Media module
  2. Go to Manage form display for the Image media-type, drag the Name from the Disabled section into the top section, and click Save
  3. Create a new media-entity of type Image with Alternative text (e.g. "Alt Text 1") and Name (e.g. "Name 1")
  4. Edit the media-entity, remove the image, and add it again
  5. Note that the Name reverts to the filename on saving

Proposed resolution

If there's already a name filled on the content and it is not the name of the uploaded file, do not override it when re-uploading the file.

Remaining tasks

Send a patch
Test it
Commit

User interface changes

Only fix the problem with the Name field.

API changes

-

Data model changes

-

Release notes snippet

-

🐛 Bug report
Status

Closed: duplicate

Version

11.0 🔥

Component
Media 

Last updated 3 days ago

Created by

🇬🇧United Kingdom robbm

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.

  • 🇦🇺Australia Stephen Ollman Canberra

    #39 also did the trick for me

    I needed to un-map that field at /admin/structure/media/manage/document to stop the Media name from being overwritten each time i updated the file.

  • 🇳🇱Netherlands seanB Netherlands

    Since not mapping the title field (explained in #39) is probably the best solution, can we close this issue?
    Maybe we need to somehow make this clear through documentation or somewhere in the interface? Any thoughts?

  • 🇪🇸Spain marcoscano Barcelona, Spain

    +1 for closing this and relying on the mapping of fields to work as expected.

    I agree though that many people won't know this immediately, and I am having a hard time trying to think of a good place to document this... The best I can think of is https://www.drupal.org/docs/8/core/modules/media/creating-and-configurin... , but that too, isn't too discoverable. Another option could be some help text in the media type config form, but this is really only specific to File/Image media types...

  • 🇺🇸United States smustgrave

    Ran into this issue today and #39 solved it for me! So think it can be closed.

  • 🇮🇳India u_tiwari

    What does exactly un-map mean? Is it that if the lets say for a field "Skip Field" is set, it is un mapped?

  • 🇩🇪Germany Anybody Porta Westfalica

    I can confirm this issue still exists in latest Drupal 10 stable.

    @seanB I disagree closing this, because it's definitely a bug that only happens with translations. The original language behaves entriely correct! If the name field is filled already and you edit the name, it's not getting replaced by the file name. Just like the description of the setting says:

    Media sources can provide metadata fields such as title, caption, size information, credits, etc. Media can automatically save this metadata information to entity fields, which can be configured below. Information will only be mapped if the entity field is empty.

    The bold part is broken with translations enabled! That needs to be fixed.
    Also translated media should keep their filled media name on save and not reset!

  • Status changed to Closed: duplicate 6 months ago
  • 🇧🇪Belgium mr.baileys 🇧🇪 (Ghent)

    Agreed with @Anybody that current behavior when saving a translation of a media entity still is buggy. However, since in this IS there is no mention of translations, I think this issue should be closed as a duplicate of 🐛 Mapped media fields are overridden with metadata on translation save Needs review , which addressed fields being overwritten when saving a translation of a media entity.

Production build 0.71.5 2024