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.