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

CommentFileSizeAuthor
#2 3294883-2.patch997 bytesmarcoscano

Comments

marcoscano created an issue. See original summary.

marcoscano’s picture

Assigned: marcoscano » Unassigned
Status: Active » Needs review
StatusFileSize
new997 bytes

I'm having an error when trying to open a fork, so I'm going old-patch style for now.

seanb’s picture

Status: Needs review » Reviewed & tested by the community

Nice catch!

  • catch committed ad751b4 on 10.0.x
    Issue #3294883 by marcoscano: Fix inaccurate code comment in Media.php...
  • catch committed 69f148f on 10.1.x
    Issue #3294883 by marcoscano: Fix inaccurate code comment in Media.php
    
  • catch committed c1cd3dc on 9.5.x
    Issue #3294883 by marcoscano: Fix inaccurate code comment in Media.php...
catch’s picture

Committed/pushed to 10.1.x, cherry-picked to 10.0.x, 9.5.x, 9.4.x, thanks!

  • catch committed f4071d3 on 9.4.x
    Issue #3294883 by marcoscano: Fix inaccurate code comment in Media.php...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.