Active
Project:
Drupal core
Version:
main
Component:
media system
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
24 Sep 2019 at 13:53 UTC
Updated:
9 Sep 2023 at 15:10 UTC
Jump to comment: Most recent
After exposing media image's name field and translating it, it gets overwritten by the default field mapping.
(Removing the default field mapping for the Name field, resolves this issue)
Steps to reproduce:
Because of default field mapping of the Name field, it overwrites manual changes.

Translating the image:

After translation it keeps the filename as its Name instead of getting the new translation

When name of image is manually entered, it shouldn't get overwritten by field mapping.
| Comment | File | Size | Author |
|---|---|---|---|
| media-image-name-doesnt-get-translated.png | 104.44 KB | shaal | |
| translating-english-media-image-to-spanish.png | 121.53 KB | shaal | |
| admin-structure-media-manage-image--field-mapping.png | 151.41 KB | shaal |
Comments
Comment #2
shaalComment #3
seanbI think this is more a matter of explaining behaviour than actually changing it.
I would personally prefer option 2.
Comment #4
shaal@seanB after exposing Name field it IS possible to write a custom title for the media image, but translating that title is not possible.
So that's confusing.
If having the field mapping as it is wouldn't allow changing the title even in the original language, then at least there was consistency.
Comment #5
seanbWhile saving we only update the metadata when a field is empty or when the source field changes:
For a new translation the source field is changed, so then it will overwrite the mapped fields. If you would try to change the title of the translation a second time it would probably work until you change the source field again.
It is still not a good idea to expose mapped fields imho.
Comment #6
andrewmacpherson commentedIt's OK for a site builder to un-map the name field if they want to, right? Then authors would always have to provide the name manually.
Comment #7
seanbThat is definitely OK! I have built sites that do exactly that myself. We wanted a super easy form out-of-the-box so we mapped the name field by default, but removing a mapping is no problem at all.
Comment #8
berdir> It is still not a good idea to expose mapped fields imho.
Well, if that's not recommended, then what's the point of even having it translatable :) That will make it even harder to distinguish translations on the table overview?
I still think that the approach that we're working with, which only fills the name field when it was empty instead of an "enforced" mapping is a better solution for the media name.
Comment #9
seanbIt depends, if the source field is translatable it could still fetch the title from the media source. For example youtube video's uploaded in multiple languages with a custom title for each one. If we only overwrite empty titles or not allow translations for mapped fields the translated video would not get its title updated.
In the current implementation, mapped fields should not be manually changed. I'm open to changing that, but that would complicate the behaviour of mapping. It might be better to just explain what the mappings do and warn users exposing mapped fields.
Comment #11
berdir> In the current implementation, mapped fields should not be manually changed. I'm open to changing that, but that would complicate the behaviour of mapping.
That's also how the configuration in standard works and I agree that umami should then decide if it either wants to happen and if so, hides the field.
But I still think that's problematic in a multilingual context, when we show all translations in the list.
> It might be better to just explain what the mappings do and warn users exposing mapped fields.
The limitation is that core currently black & white. Either you map, the you must hide the field, or you dont' and show it but then it is required and users are forced to provide a name manually.
As mentioned in the issue that made this the default configuration for standard, what we do instead in our install profile is a form alter that makes the fields optional and then rely on the fallback logic instead to fill it out. But that *only* happens initially and if it's empty.
A fancier version of that would be to implement that in javascript somehow, of course not trivial to do that generically.
Comment #12
xjmProbably a major bug given the lost user input (however we address it).
Comment #13
berdirI'd say if bug, then "only" in umami, to hide the media field, and I think that's only in the not-yet-committed umami/media patch?
That is the behavior that was chosen, as (optional, since media is not yet required) default configuration in standard, so I think as a minimum step, umami would just need to be kept in sync with that.
The things I'm talking about is probably a feature.
Comment #14
shaal@berdir Umami patch for working with media images is already 'solving' this problem (#2954378: Use Media images in Umami demo)
As a user, it confused me as it is not intuitive, of why enabling/exposing the name field doesn't let me give it the title I want.
Comment #15
seanbI would say the behaviour makes sense. I would consider it a bug if a source field was mapped and the title was not updated.
That being said, I agree this behaviour is not intuitive and we could improve this by warning users when they expose mapped fields in forms.
Comment #16
shaalPerhaps this is a bad example, but I thought of a behavior (by default) similar to https://www.drupal.org/project/auto_entitylabel
If the name field is left empty the system will generate a name (based on the filename).
Comment #21
larowlanSounds like we need to decide
- if this is a bug
- is it only a bug in umami
- what can we do to prevent site builders getting into this mess
- do we want a feature request to support the ideas from #11
Comment #22
stborchertWe are also experiencing this behavior during a migration of media items (Core version 9.3.x) so I wouldn't say it's related to Umami only.
Each translation has a different image attached to the media item. When saving the entity (
MigrateExecutable::import() -> Media::prepareSave()the translated name set by the migration is overridden by the file name of the source file (becauseMedia::hasSourceFieldChanged()returnsTRUE).We (kind of) solve this right now by adding an additional presave hook that sets the name back to its correct value.
--Update
Seems like skipping the "Name" field in the field configuration of the media source fixes the problem for us (see https://www.drupal.org/project/drupal/issues/2999370#comment-13055698).
Comment #26
smustgrave commentedShould this be reopened per #22?
Comment #27
chris matthews commentedThis bug report looks like a duplicate of #2999370: Mapped media fields are overridden with metadata on translation save so maybe this issue could be re-scoped to address what we can do to prevent site builders getting into this mess.
- if this is a bug
- is it only a bug in umami
- what can we do to prevent site builders getting into this mess
- do we want a feature request to support the ideas from #11