Problem/Motivation

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:

  • (optional) Setup Drupal using Umami installation
  • Exposed the title (Name) of image media.
  • Enabled translation for image media.
  • Add an image and give it a title.
  • Clicked on 'translate', and translate both title and alternative text.
  • The title does not get translated :(

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

Proposed resolution

When name of image is manually entered, it shouldn't get overwritten by field mapping.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

shaal created an issue. See original summary.

shaal’s picture

Issue summary: View changes
seanb’s picture

I think this is more a matter of explaining behaviour than actually changing it.

  1. We could add a message to mapped fields, explaining their values would be overwritten. Since editor can't do anything about it this is probably not preferable.
  2. We could also add some message to the form display page. When site builders expose a mapped field, a warning could be added explaining the behaviour.

I would personally prefer option 2.

shaal’s picture

@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.

seanb’s picture

While saving we only update the metadata when a field is empty or when the source field changes:

// Only save value in entity field if empty. Do not overwrite existing
// data.
if ($translation->hasField($entity_field_name) && ($translation->get($entity_field_name)->isEmpty() || $translation->hasSourceFieldChanged())) {
  $translation->set($entity_field_name, $media_source->getMetadata($translation, $metadata_attribute_name));
}

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.

andrewmacpherson’s picture

It'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.

seanb’s picture

It'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.

That 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.

berdir’s picture

> 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.

seanb’s picture

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?

It 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.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

berdir’s picture

> 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.

xjm’s picture

Priority: Normal » Major

Probably a major bug given the lost user input (however we address it).

berdir’s picture

I'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.

shaal’s picture

@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.

seanb’s picture

I 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.

shaal’s picture

Perhaps 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).

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

larowlan’s picture

Status: Active » Postponed (maintainer needs more info)
Issue tags: +Needs issue summary update, +Bug Smash Initiative

Sounds 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

stborchert’s picture

We 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 (because Media::hasSourceFieldChanged() returns TRUE).

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).

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Should this be reopened per #22?

chris matthews’s picture

Status: Postponed (maintainer needs more info) » Active

This 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

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.