Problem/Motivation

A media title is overridden with filename after saving of media translation with different image for target language

To reproduce:

  • Install Drupal 8.6.0 in English
  • Enable these modules: Core: Media, Multilingual: Content Translation
  • Add a language ( /admin/config/regional/language )
  • Check the 'Media' custom language settings in /admin/config/regional/content-language and make image media type translatable (translation for Image field should be enabled too).
  • Add an image (/media/add/image) and translate it: upload different image and change title

Actual result: media title is overridden with file name in translation.

I guess there is mistake in Media::prepareSave() method:

        foreach ($translation->bundle->entity->getFieldMap() as $metadata_attribute_name => $entity_field_name) {
          // 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));
          }
        }

Looks like current condtition is not OK, and OR condition should be replaced with AND condition:

if ($translation->hasField($entity_field_name) && ($translation->get($entity_field_name)->isEmpty() && $translation->hasSourceFieldChanged())) {

In this way title will be overridden only in case when it is empty.

Proposed resolution

Remaining tasks

Update summary
Review

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#124 2999370-nr-bot_bigu2bcy.txt90 bytesneeds-review-queue-bot
#118 2999370-mapped-media-fields-fix-10.x-patch-118.patch6.88 KBteknocat
#117 Screencast from 2025-12-01 16-53-18.mp45.48 MBtcrawford
#116 2999370-mapped-media-fields-fix-11.x-patch-116.patch7.18 KBgrevil
#109 change_metadata_after_source_entity_change_fix.patch741 bytesdidebru
#107 change_metadata_after_source_entity_change_fix.patch0 bytesdidebru
#74 drupal-2999370-74-1002-mapped_media_fields_overridden_with_metadata_on_translation_save.patch3.73 KBHAL 9000
#71 2999370-71.patch1.37 KBAjeet Tiwari
#70 drupal-mapped_media_fields_overridden_with_metadata_on_translation_save-2999370-70.patch2.91 KBndewhurst
#69 drupal-mapped_media_fields_overridden_on_translation_save-2999370-69.patch2.54 KBndewhurst
#62 2999370-62.patch4.25 KBMunavijayalakshmi
#57 2999370.png62.35 KBpcambra
#53 2999370-53.patch3.81 KBpcambra
#52 2999370-52.patch3.81 KBpcambra
#40 interdiff_38-40.txt765 bytesvsujeetkumar
#40 2999370_40.patch6.25 KBvsujeetkumar
#38 interdiff-37-38.txt4.35 KBcodersukanta
#38 2999370-38.patch5.37 KBcodersukanta
#37 2999370-37.patch1.02 KBkiseleva.t
#31 After.mp412.79 MBpriyanka.sahni
#31 After_3.png112.83 KBpriyanka.sahni
#31 After_2.png107.76 KBpriyanka.sahni
#31 After_1.png284.11 KBpriyanka.sahni
#31 Before_3.png110.4 KBpriyanka.sahni
#31 Before_2.png118.87 KBpriyanka.sahni
#31 Before_1.png264.28 KBpriyanka.sahni
#29 2999370-28.patch1.55 KBmarthinal
#27 Screenshot 2020-06-10 at 07.07.46.png131.79 KBmarthinal
#27 Screenshot 2020-06-10 at 07.07.37.png192.19 KBmarthinal
#27 Screenshot 2020-06-10 at 07.06.06.png124.32 KBmarthinal
#27 Screenshot 2020-06-10 at 07.05.57.png181.15 KBmarthinal
#24 2999370-24.patch548 bytesmarthinal
#19 2999370-19.patch549 bytesneelam_wadhwani
#18 media_image_name_override-2999370-5.patch540 bytesmaheshpa
#16 interdiff-14-16.txt746 bytesfranz
#16 media-translation-title-override-2999370-16.patch1.95 KBfranz
#14 media-translation-title-override-2999370-14.patch1.91 KBmatroskeen
#11 interdiff_06-11.txt831 bytesckaotik
#11 interdiff_08-11.txt2.94 KBckaotik
#11 media-translation_hassourcefieldchanged-2999370-11.patch1 KBckaotik
#8 media-translation_hassourcefieldchanged-2999370-8.patch2.92 KBursegol
#8 interdiff-2999370-06-08.txt2.93 KBursegol
#6 media-translation_hassourcefieldchanged-2999370-6.patch1012 bytesckaotik
#4 media-translation_hassourcefieldchanged-2999370-4.patch963 bytesckaotik
#2 media-title-is-overridden-with-metadata-on-translation-save-2999370-2.patch948 bytesafi13

Issue fork drupal-2999370

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

afi13 created an issue. See original summary.

afi13’s picture

Status: Active » Needs review
StatusFileSize
new948 bytes

Status: Needs review » Needs work
ckaotik’s picture

Status: Needs work » Needs review
StatusFileSize
new963 bytes

I think the operator is correct, as any mapped fields get overridden if the "source value" changes. So if you have mapped the media name, that logic applies there, too. If you change the title and the image file at the same time, and have a mapping for the media title, the title will get overridden - that is intentional.

Scenario 1: The media name is not translatable and the translation's file was changed.
Saving a translation will also override the media name. Mapped fields should probably all be marked as translatable, if the file field is.

Scenario 2: The media name is translatable, and the translation's file was changed.
Saving the translation will also override the media name, because the file has changed and thus mappings need to be re-evaluated.

Scenario 3: The media name is translatable, and the translation's file was not changed in the translation.
This is a troublesome case, because $translation->hasSourceFieldChanged() always checks against the default language, instead of the translation. So if you have a different image for each language (think: the flag of the language's associated country), and change a translation's title, it will get overridden again - simply because `flag_xx.png` (in the translation) is different from `flag.png` (in the default language).

I've attached a patch to try and avoid this, but it probably isn't the perfect solution yet and we most definetely need tests for this.

Status: Needs review » Needs work
ckaotik’s picture

Status: Needs work » Needs review
StatusFileSize
new1012 bytes

Fixed error if translation does not exist (yet).

Status: Needs review » Needs work
ursegol’s picture

Status: Needs work » Needs review
StatusFileSize
new2.93 KB
new2.92 KB
if (!isset($this->original) && $id = $this->id()) {
      $this->original = $this->entityTypeManager()
        ->getStorage('media')
        ->loadUnchanged($id);
    }

Was not executed when a new medium was created, thus $original = $this->original; led to $original to be NULL. This in returned led to an error while checking if the $original has a translation.
Fixed by only executing the search for the right translation, if $original is an object.

ursegol’s picture

if (!isset($this->original) && $id = $this->id()) {
      $this->original = $this->entityTypeManager()
        ->getStorage('media')
        ->loadUnchanged($id);
    }

Was not executed when a new medium was created, thus $original = $this->original; led to $original to be NULL. This in returned led to an error while checking if the $original has a translation.
Fixed by only executing the search for the right translation, if $original is an object.

Status: Needs review » Needs work
ckaotik’s picture

Status: Needs work » Needs review
StatusFileSize
new1 KB
new2.94 KB
new831 bytes

I missed that case, didn't test thoroughly it seems, thanks for spotting it! I've added a check for that to my previous patch, so we don't need the extra nesting level in the code.

junaidpv’s picture

We are also facing this issue. Our site does not have any translation related modules enabled.

I think there should be a way to allow user to override "Name" field even filename metadata is mapped to it. So, metadata mapping would occur only if user did not provide custom value for that field.

phenaproxima’s picture

Issue tags: -media

Removing unnecessary "media" tag.

matroskeen’s picture

In my opinion, metadata should be used as a fallback. So, if there is any value in the field, metadata should be ignored.

We have a similar description in the "FIELD MAPPING" section settings:
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.

Tests will likely fail, but let's see.

matroskeen’s picture

Version: 8.6.x-dev » 8.8.x-dev
franz’s picture

Previous patch didn't work for adding a translation where it didn't exist before.

Status: Needs review » Needs work

The last submitted patch, 16: media-translation-title-override-2999370-16.patch, failed testing. View results

maheshpa’s picture

StatusFileSize
new540 bytes

I investigated this issue and I found solution and worked for me. This issue arisen because media entity name attribute returning the file name so media name override by file name while rendering the media entity info. I hope attached patch helpful to you and revert me if need any help.

neelam_wadhwani’s picture

StatusFileSize
new549 bytes

Hello @maheshpa

The patch need re-roll.
Kindly review the updated patch.

neelam_wadhwani’s picture

Status: Needs work » Needs review
Issue tags: +Quickfix Need Reroll

Status: Needs review » Needs work

The last submitted patch, 19: 2999370-19.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

maheshpa’s picture

Status: Needs work » Needs review
phenaproxima’s picture

Status: Needs review » Needs work

The patch is still failing tests, so this still needs work. Sorry!

marthinal’s picture

Version: 8.8.x-dev » 8.9.x-dev
Status: Needs work » Needs review
StatusFileSize
new548 bytes

I'm running the tests locally and those are green. Let's try again

Status: Needs review » Needs work

The last submitted patch, 24: 2999370-24.patch, failed testing. View results

marthinal’s picture

marthinal’s picture

We break the tests because the expected behavior is to update the name. But TBH this is very confusing for users:

1- Add media


2- Update alt text

3- The name has been updated

marthinal’s picture

Issue tags: -Quickfix Need Reroll
marthinal’s picture

Status: Needs work » Needs review
StatusFileSize
new1.55 KB

I think we shouldn't update the name if the user has changed that value from the UI. Let's try something like this.

priyanka.sahni’s picture

Assigned: Unassigned » priyanka.sahni
priyanka.sahni’s picture

StatusFileSize
new264.28 KB
new118.87 KB
new110.4 KB
new284.11 KB
new107.76 KB
new112.83 KB
new12.79 MB

Verified and tested by applying the patch #29.It looks good to me.Can be moved to RTBC.

Steps to test -
1. Go to the admin site.
2. Go to admin/modules.
3. Enable Media and Multilingual languages.
4. Go to admin/config/regional/language.
5. Add another language.
6. Go to admin/config/regional/content-language.
7. Enable Media in Custom language settings and Save it.
8. Go to admin/structure/media/manage/image/fields/media.image.field_media_image.
9. Enable the Alternative text and Save settings.
10. Go to admin/content/media.
11. Add media type and enter text in Name and Choose Image.
12. On choosing image add Alternative text.
13. Save it.
14. Edit the saved media type and change the Alternative text.
15. Verify the listing page.

Refer to the attached screenshots and video.

Before Patch -
Step 1 -
BeforePatch

Step 2 -
BeforePatch

Step 3 -
BeforePatch

After Patch -
Step 1 -
After Patch

Step 2 -
After Patch

Step 3 -
After Patch

priyanka.sahni’s picture

Assigned: priyanka.sahni » Unassigned
Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 29: 2999370-28.patch, failed testing. View results

phenaproxima’s picture

phenaproxima’s picture

Priority: Normal » Major
Issue tags: +Media Initiative, +Triaged Media Initiative issue

Escalating the priority of this issue, as it looks like it might cause unintentional data loss.

tvb’s picture

During a migration of media document translations this issue (assigned media name is overwritten with filename) popped up.

Removing the field mapping for Name (set to '- Skip field -') on admin/structure/media/manage/document avoids the issue from occurring.

The patch from #29 also resolves the issue in case the field mapping for Name is set to 'Name'. (drupal core 8.9.3)

kiseleva.t’s picture

StatusFileSize
new1.02 KB

The issue appeared for me in the case when the source field is not the name field, but some other.
The patch attached solved the problem for that case.

codersukanta’s picture

Status: Needs work » Needs review
StatusFileSize
new5.37 KB
new4.35 KB

Worked on testcase failures, Please review.

Status: Needs review » Needs work

The last submitted patch, 38: 2999370-38.patch, failed testing. View results

vsujeetkumar’s picture

Status: Needs work » Needs review
StatusFileSize
new6.25 KB
new765 bytes

Fixed tests, Please review.

efrainh’s picture

I tested #29 on Drupal 8.9.9 and PHP 7.3 2 weeks ago and we didn't have this issue anymore.

matroskeen’s picture

I'm wondering if #3192059: Use the source field main property to determine if the source field has changed did the trick and resolved the issue we're struggling here 🤔
Would be great if anyone can re-test in the latest 9.1.x or 9.2.x.

mikran’s picture

Title: Media title is overridden with metadata on translation save » Mapped media fields are overridden with metadata on translation save
Status: Needs review » Reviewed & tested by the community

I've tested this on Drupal 9.2.8, and #3192059: Use the source field main property to determine if the source field has changed does not fix the issue.

I'm also updating the title of this ticket, problem is not limited to media title. All mapped media fields are affected by this (as mentioned in #37).

I was testing with remote video and

The HTML representation of the resource

field mapping and without this patch I could not modify value of that field when editing a translation.

With this patch it works correctly.

phenaproxima’s picture

Status: Reviewed & tested by the community » Needs review

Thanks for testing this, everyone. I think this needs a little more review before it can be RTBC, for two reasons:

1. I don’t understand why the change in the patch fixes the problem.
2. I’m not sure why we are removing assertions from the tests. If it’s necessary to properly test the fix, that’s fine, but without understanding the nature of the fix, I can’t be sure of that. We definitely do not want to inadvertently lose precious test coverage.

mikran’s picture

Version: 8.9.x-dev » 9.2.x-dev
Assigned: Unassigned » mikran
Status: Needs review » Needs work

Thanks @phenaproxima for comments, I did more testing with it - and you're right. It does not fix the problem.

The patch fixed the problem of alterations being overridden, but it now stopped doing the mapping if source changes.

phenaproxima’s picture

Issue tags: +Needs tests

What I think might be better here is to first add completely new test coverage that proves the problem exists (i.e., an automated test that fails). Then, knowing that we are reproducing the problem consistently with a test, we can get to work finding a proper fix for the bug. Therefore, marking this as "needs tests".

phenaproxima’s picture

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

Changing the branch target to 9.4.x, where all new development is taking place. This can be backported to 9.3.x at committer discretion.

phenaproxima’s picture

Hiding patches in favor of using the merge request workflow. It's a lot easier to review changes that way.

Don't worry, everyone who worked on the patch will still get credit at commit time. :)

mikran’s picture

Status: Needs work » Needs review

oh I was working on it too :)

anyway here is a fix for it from comment 11 - that looks good. And I've updated test to do one more save. I think it is correct that mapped field gets forcibly overridden when you change the source, but any subsequent save should then retain the changed values.

mikran’s picture

Assigned: mikran » Unassigned
pcambra’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new3.81 KB

I've been experiencing this issue with the following workflow:

- Multilanguage site, but no translation involved.
- Create media attached to a node through entity reference. User enters the name of the media in the entity form.
- Media source is not immediately added as it is too large and it is processed (details don't matter, what matters is that media is created without source).
- When the async process finishes, it saves the media entity, and replaces the user entered name field by the media file name.

This can be reproduced by having to media entity form modes, one without file, and one with file. Create the media without file, enter the name and then save it again with file.

The latest code on the MR does not fix the issue but the change in #2 does. I think @phenaproxima failing test is correct.

Rather than changing the MR, I'm adding a patch so I'm not stepping over anyone, please lmk if the patch makes sense and I'll move it to the MR :)

pcambra’s picture

StatusFileSize
new3.81 KB

F in spelling

mikran’s picture

Status: Reviewed & tested by the community » Needs review

The latest code on the MR does not fix the issue but the change in #2 does. I think @phenaproxima failing test is correct.

The response (comment #4) for comment #2 states that "If you change the title and the image file at the same time, and have a mapping for the media title, the title will get overridden - that is intentional." I agree with that especially when taking all of the mapped fields into an account. It could be argued that non-empty title should remain even if source is changed, but this code in question applies to all of the mapped fields. So in case of video source, if you change the source should the title be updated? what about the thumbnail? HTML embed code? other mapped fields?

I've modified the test with that in mind and the customized title is set in a subsequent save after the media is first saved with just the changed source property.

Rather than changing the MR, I'm adding a patch so I'm not stepping over anyone, please lmk if the patch makes sense and I'll move it to the MR :)

Thanks for that! To me #2 and #52 looks like different issue, where the automatic mapping for title that can not be turned off is causing the problem.

pcambra’s picture

(sorry for the RTBC, no idea how that happened)

Makes sense, happy to open a followup if there's consensus, should that be a flag on the title/name replacement?

Status: Needs review » Needs work

The last submitted patch, 53: 2999370-53.patch, failed testing. View results

pcambra’s picture

StatusFileSize
new62.35 KB

@mikran you were absolutely right, as it's mentioned on #4, what I've described on #52 only happens when you map the fields in the media entity itself, I've configured it as the screenshot and all works as expected:

Leaving this comment here in case someone else finds it useful

mikran’s picture

Status: Needs work » Needs review

Setting back to Needs review for Merge request 1392

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.

jonmcl’s picture

I came to this issue while researching a similar problem. However, in our case we do not have translation enabled. The problem seems to still happen with the x-default language. I tried this patch anyway and it doesn't work when no translation is enabled.

I then found #3157183: Contents of Name field replaced by default value (i.e filename) and I'm wondering if that patch might fix this problem too? Just putting this comment here incase that patch fixes translations as well.

UPDATE: I found a test, MediaSourceImageTest::testOnlyMainPropertiesTriggerSourceFieldChanged, that as an assertion that the entity name SHOULD change when a new file is uploaded. That test is currently causing #3157183: Contents of Name field replaced by default value (i.e filename) to fail tests. For that reason, I'm not sure that is is an appropriate fix and I'm wondering if the intended functionality of the media module is to ALWAYS force a document name change when the file name is change, but only when the field mapping exists.

rar9’s picture

Patch #53 is no longer working with core 9.45

Munavijayalakshmi’s picture

Assigned: Unassigned » Munavijayalakshmi
StatusFileSize
new4.25 KB

#53 patch Re-rolled (9.5.x).

Status: Needs review » Needs work

The last submitted patch, 62: 2999370-62.patch, failed testing. View results

Munavijayalakshmi’s picture

Assigned: Munavijayalakshmi » Unassigned

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.

ayalon’s picture

Status: Needs work » Reviewed & tested by the community

I have tested patch #62 with Drupal 9.5.3 and it successfully resolves the issue, that you cannot change the name ov a previously saved media entity translation.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 62: 2999370-62.patch, failed testing. View results

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.

ndewhurst’s picture

The patch in #62 prevents the specific problem outlined in the description, but it introduces a regression. Specifically, metadata will never be mapped to entity fields, even if those fields are empty, unless the source field changes. This does not appear to match the original intent here.
It might not be a noticeable issue for most people because most metadata won't change unless the media source changes - e.g. if you edit an Image-sourced media entity and replace the image file. However, it's perfectly valid for there to be all sorts of other metadata that might be updated somewhere without the media source changing - e.g. a transcript on an externally-hosted video, a caption for an image stored in an external DAM, etc.
I wonder if we could restate the problem by defining the expected behavior as:

Available metadata should always be used to populate mapped fields when media entities are saved/resaved and the target fields are empty. When changing a media source field, we should expect any mapped fields to be updated with metadata-derived values, unless we are simultaneously providing alternative values for some of those fields.

I know it doesn't avoid the "I previously customized the media name, and I was hoping my custom name would persist after replacing the source file" scenario...but it seems to balance the concerns in this thread with the original intent.
Here's a patch that tries to put the aforementioned behavior into practice. If someone is able to look at tests for it or otherwise weigh in, that would be cool.

Edit: see #70 for better patch.

ndewhurst’s picture

Updating patch to work with new media entity creation, improve empty value handling, and revise comments.

Ajeet Tiwari’s picture

Status: Needs work » Needs review
StatusFileSize
new1.37 KB

Please review.

Status: Needs review » Needs work

The last submitted patch, 71: 2999370-71.patch, failed testing. View results

ndewhurst’s picture

+++ b/core/modules/media/src/Entity/Media.php
@@ -433,7 +432,7 @@ public function prepareSave() {
-          if ($translation->hasField($entity_field_name) && ($translation->get($entity_field_name)->isEmpty() || $translation->hasSourceFieldChanged())) {
+          if ($translation->hasField($entity_field_name) && ($translation->get($entity_field_name)->isEmpty() && $translation->hasSourceFieldChanged())) {

@Ajeet Tiwari - this proposal is the same as in #2. I don't believe this is good, because mapped fields that are empty should be eligible for population regardless of whether the source field is changing.

HAL 9000’s picture

Hi, 62's patch has been re-rolled to work with 10.2.

anybody’s picture

I can sadly confirm this issue in all multilanguage projects.

@ndewhurst you say the patch in #70 is superior. Should this be turned into a MR against 11.x then and also implement tests (eventually the test copied from the existing MR?)

I agree this is major for all multilingual projects!

Grevil made their first commit to this issue’s fork.

grevil’s picture

Ok, I manually applied patch #70 by @ndewhurst on a new issue branch and created an MR against current 11.x. I'll take a closer look at the patch tomorrow and see if I can get the existing tests to work for the new branch.

grevil’s picture

Ok something went wrong. I'll get back to it tomorrow.

Anybody changed the visibility of the branch 11.x to hidden.

Anybody changed the visibility of the branch 9.3.x to hidden.

Anybody changed the visibility of the branch 11.x to active.

anybody’s picture

@Grevil: This was indeed pain! I was finally able to apply #70 with MR !8973 (11.x - sorry for the bad naming).
I think we can now proceed there and hide / close the other MR's?

Grevil changed the visibility of the branch 2999370-mapped-media-fields-11.x to hidden.

Grevil changed the visibility of the branch 2999370-mapped-media-fields to hidden.

grevil’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

MR! 8983, containing the changes of patch #70 and the test provided with patch #62 seems to work great! The new code is a bit harder to read, but I see no caveats with it on my end.

Unsure if the provided test is enough, or if we should somehow recreate the case mentioned by @ndewhurst in #69:

However, it's perfectly valid for there to be all sorts of other metadata that might be updated somewhere without the media source changing - e.g. a transcript on an externally-hosted video, a caption for an image stored in an external DAM, etc.

Setting this to "Needs Review" for now, so a core maintainer can decide if the provided test is enough.

anybody’s picture

@Grevil: I tried if the "Test only" functionality in the Pipeline can help here to show the test-only test fails (https://git.drupalcode.org/issue/drupal-2999370/-/pipelines/239344/) but I'm not familiar enough with that. So could you eventually post a test-only branch to show the test fails without the fixes? Or do you know how to do that correctly?

grevil’s picture

See output of 2999370-mapped-media-fields-fix-11.x-test-only, the test fails without the changes as expected! 🎉

anybody’s picture

Status: Needs review » Reviewed & tested by the community

Yeah GREAT @Grevil! RTBC for MR !8983!
Would still be good if others here could also test the MR for edge-cases, so we can get this fixed finally. Thank you!

quietone’s picture

Issue summary: View changes

I do like the older issue getting fixed. Thanks for getting this to RTBC.

I've added the standard template to the issue summary, can someone fill out the proposed resolution here.

I reviewed the MR and left some suggestions and questions there. Setting to needs work for that.

quietone’s picture

Status: Reviewed & tested by the community » Needs work
grevil’s picture

Status: Needs work » Needs review

Alright, adjusted the code based on the suggestions by @quietone. Please review once again!

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Believe feedback has been addressed on this one.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I've added some comments on the MR to address.

anybody’s picture

Status: Needs work » Needs review
alexpott’s picture

Added another suggestion to the MR.

anybody’s picture

Status: Needs review » Needs work
grevil’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

There are 2 MRs could one be hidden please.

Assuming the one to review is 8983 but that one appears to have test failures, moving to NW for investigation.

grevil changed the visibility of the branch 2999370-mapped-media-fields-fix-11.x-test-only to hidden.

grevil’s picture

Status: Needs work » Needs review

Simple rebase fixed it again. Back to needs review!

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs issue summary update

My mistake should of noticed before but issue summary is incomplete.

didebru’s picture

For me the MR did not apply on 11.1.5.

I had a similiar issue that if the source file is different on the translation than the name would not be updated and always gets the new source file title.

My WA would be to check on the $_POST variable but that feels like a real ugly hack.

I did insert this in Media::prepareSave():463

if ($this->activeLangcode === $langcode && $_POST['name'][0]['value'] ?? '' !== $translation->getName()) {
        $translation->setName($_POST['name'][0]['value']);
      }
didebru’s picture

Here is the patch with the hacky approach.

didebru’s picture

didebru’s picture

didebru’s picture

didebru’s picture

Updated the MR to latest 11.x forget about what I wrote earlier :D

didebru’s picture

Ok the MR solves the issue for 2 languages but not for > 2 e.g.
If you have configured de, it and fr and you will change the title for de (which is the default language) the last edited translation title will change back to the filename.

didebru’s picture

For me it is working if I remove the strict comparison check and only act if the old value is empty.
Maybe I'm too dumb but what is the benefit if we update the field with the default metadata if it does not change?

grevil’s picture

@didebru

Ok the MR solves the issue for 2 languages but not for > 2 e.g.
If you have configured de, it and fr and you will change the title for de (which is the default language) the last edited translation title will change back to the filename.

So with 3 languages you mean one original entity + 2 translations? I adjusted the tests and they seem to succeed. Any suggestions on how to improve the tests?

grevil’s picture

Status: Needs work » Needs review

Ok, tests are green again. Unsure about the comment from @martins.bertins (https://git.drupalcode.org/project/drupal/-/merge_requests/8983#note_404381). Couldn't replicate this behavior. A test or clear steps to reproduce would be nice.

Setting back to needs review for now though.

grevil’s picture

Static patch for the time being. We will test it internally as well and come back here if any issues occur.

tcrawford’s picture

StatusFileSize
new5.48 MB

I have not written a test to replicate the behavior, but you can see in the video that it occurs when translating to the third language (base + 2nd translation), but without uploading a new image that the name of the 1st translation (not the base) is overwritten.

Video of showing issue

Please disregard the noise. I thought I had #116 applied, but it was not properly applied. I had an older patch. Checking again and will report findings.

teknocat’s picture

The current patch, as well as the one from comment 116, doesn't apply properly in D10 any more - the conflicts are in the Kernel test. I've re-rolled the patch against Drupal 10.x for those who need it.

anybody’s picture

@teknocat thanks, if possible let's please instead (or additionally) keep the MR up to date and finish it, so this can be finalized. Thanks!

marcoscano’s picture

I opened #3567230: Only overwrite mapped field values on media items when source field original value was non-empty today which overlaps with this one, but it's a different issue. Whichever gets in first, the other will need a re-roll.

teknocat’s picture

When I re-rolled the patch in my comment #118, I failed to realise that was not actually compatible with D10, which doesn't have the normalized getOriginal() API method. Not quite sure how I missed that until our client flagged errors when uploading media entities in their site (doh!).

@anybody how would you prefer a D10-compatible patch be handled in the short-term? I could just upload a re-rolled one. I understand that issues should always be opened against the current core development branch, but if D10 and D11 are both currently supported and sometimes need different patches to solves the same issues, like in this case, I'm not sure what makes the most sense to make it easy to manage and avoid any confusion around it.

teknocat’s picture

Also I think I actually uploaded the wrong copy of the patch file I rolled for D10 compatibility. I just double checked my local codebase where I was working on the patch, where it needs to use $this->original for D10 and not $this->getOriginal(). (facepalm).

But before I upload a correct D10 version, I'd still like to know the best practice per my previous comment about a case like this.

thomas.frobieter’s picture

This really is one of the most frustrating Drupal issues ever. It's particularly frustrating for site editors. It would be much appreciated if this could be fixed soon (created 13 Sep 2018).

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

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.

anybody’s picture

a_mitch made their first commit to this issue’s fork.

a_mitch’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

This one still appears to need issue summary update.