Change record status: 
Project: 
Introduced in branch: 
8.5.x
Introduced in version: 
8.5.0-alpha1
Description: 

Currently, to get the value of the source field of a media entity, you must write code similar to this:

    $source_field = $this->getSourceFieldDefinition($media->bundle->entity)->getName();
    /** @var \Drupal\Core\Field\FieldItemInterface $source_field_item */
    $source_field_item = $media->get($source_field)->first();

    $main_property = $source_field_item->mainPropertyName();
    $source_field_value = $source_field_item->get($main_property)->getString();

As of #2934966: Make it easier to get source field values from media items, a new method has been added to MediaSourceInterface called getSourceFieldValue(), which returns the value of a media entity's source field. MediaSourceBase has a generic implementation of this method which should work in almost all cases.

So now, to get the source field value, you can just do this instead:

$media_entity->getSource()->getSourceFieldValue($media_entity)

Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done