Change record status: 
Project: 
Introduced in branch: 
9.1.x
Introduced in version: 
Description: 

A new public method was added to \Drupal\media\MediaInterface that allows custom code to trigger the update of metadata for an existing media entity.

  /**
   * Update the media entity's field values from the source's metadata.
   *
   * This will fetch metadata from the source field, and update all values that
   * are mapped to entity fields. This will overwrite non-empty existing values,
   * and will update all translations of the entity. This will also try to
   * update the entity's thumbnail with a newer version, if available.
   *
   * @return \Drupal\media\MediaInterface
   *   An unsaved version of this media item, after updating the mapped field
   *   items and the thumbnail.
   */
  public function updateMetadata();

Example of custom code using this method:

  $media = Media::load(123);
  $media->updateMetadata()
    ->save();

The ability to trigger this action is now also exposed on the UI so users with permission to edit media entities can also trigger this process manually. Check #2983456: Expose triggering update of media metadata + thumbnail to end users for more details and screenshots.

Impacts: 
Site builders, administrators, editors
Module developers