\Drupal\media\MediaSourceInterface
got two new methods, ::prepareViewDisplay(MediaTypeInterface $type, EntityViewDisplayInterface $display)
and ::prepareFormDisplay(MediaTypeInterface $type, EntityFormDisplayInterface $display)
.
Both provide the source plugins with the ability to configure how their fields should be displayed in the view and form display.
\Drupal\media\MediaSourceBase
implements the new methods and sets the source field to its default widget/formatter settings.
For example, if \Drupal\media\Plugin\media\Source\Image
wanted to specify a formatter for its source field different from the field defaults, it could implement something like:
/**
* {@inheritdoc}
*/
public function prepareViewDisplay(MediaTypeInterface $type, EntityViewDisplayInterface $display) {
$display->setComponent($this->getSourceFieldDefinition($type)->getName(), [
'type' => 'image_url',
'settings' => [
'image_style' => 'thumbnail',
],
]);
}
Which would set the source field to be displayed using the image_url
formatter.