Problem/Motivation
In \Drupal\media\Entity\Media::prepareSave() we have:
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));
}
}
That inline comment is incorrect. That was probably the original intention, but we might have changed the conditional and missed updating the comment.
Proposed resolution
A more accurate comment would be:
foreach ($translation->bundle->entity->getFieldMap() as $metadata_attribute_name => $entity_field_name) {
// Only save value in the entity if the field is empty or if the
// source field changed.
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));
}
}
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comments
Comment #2
marcoscanoI'm having an error when trying to open a fork, so I'm going old-patch style for now.
Comment #3
seanbNice catch!
Comment #5
catchCommitted/pushed to 10.1.x, cherry-picked to 10.0.x, 9.5.x, 9.4.x, thanks!
Comment #7
catch