public function getSourceFile(MediaInterface $media) {
    // Get the source field for the media type.
    $source_field = $this->getSourceFieldName($media->bundle());

    if (empty($source_field)) {
      throw new NotFoundHttpException("Source field not set for {$media->bundle()} media");
    }

    // Get the file from the media.
    $files = $media->get($source_field)->referencedEntities();
    $file = reset($files);

    return $file;
  }
public function getSourceFile(MediaInterface $media) {
    // Get the source field for the media type.
    $source_field = $this->getSourceFieldName($media->bundle());

    if (empty($source_field)) {
      throw new NotFoundHttpException("Source field not set for {$media->bundle()} media");
    }

    // Get the file from the media.
    $files = $media->get($source_field)->referencedEntities();
    $file = reset($files);

    return $file;
  }
public function getSourceFile ( MediaInterface $ media ) { // Get the source field for the media type. $ source_field = $ this -> getSourceFieldName ( $ media -> bundle ( ) ) ; if ( empty ( $ source_field ) ) { throw new NotFoundHttpException ( "Source field not set for {$media->bundle()} media" ) ; } // Get the file from the media. $ files = $ media -> get ( $ source_field ) -> referencedEntities ( ) ; $ file = reset ( $ files ) ; return $ file ; }
Gets the value of a source field for a Media.

@param \Drupal\media\MediaInterface $media
Media whose source field you are searching for.

@return \Drupal\file\FileInterface
File if it exists

@throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
Gets the value of a source field for a Media .