diff -u b/core/modules/media/src/Plugin/media/Handler/File.php b/core/modules/media/src/Plugin/media/Handler/File.php --- b/core/modules/media/src/Plugin/media/Handler/File.php +++ b/core/modules/media/src/Plugin/media/Handler/File.php @@ -31,7 +31,7 @@ * {@inheritdoc} */ public function getField(MediaInterface $media, $name) { - $file = $this->getSourceFieldValue($media); + $file = $this->getSourceFile($media); switch ($name) { case 'mime': @@ -49,14 +49,14 @@ * {@inheritdoc} */ public function getThumbnail(MediaInterface $media) { - $file = $this->getSourceFieldValue($media); + $file = $this->getSourceFile($media); $icon_base = $this->configFactory->get('media.settings')->get('icon_base'); $thumbnail = FALSE; // We try to magically use the most specific icon present in the $icon_base - // directory, based on the mime information. For instance, if an icon file + // directory, based on the MIME information. For instance, if an icon file // named "pdf.png" is present, it will be used if the file matches this - // mime type. + // MIME type. if ($file) { $mimetype = $file->getMimeType(); $mimetype = explode('/', $mimetype); @@ -79,7 +79,7 @@ */ public function getDefaultName(MediaInterface $media) { // The default name will be the filename of the source_field. - return $this->getSourceFieldValue($media)->getFilename(); + return $this->getSourceFile($media)->getFilename(); } /** @@ -90,8 +90,12 @@ * * @return \Drupal\file\FileInterface * The file entity present in the source field. + * + * @throws \RuntimeException + * If the source field for the handler is not defined, or if the + * source field does not contain a file entity. */ - protected function getSourceFieldValue(MediaInterface $media) { + protected function getSourceFile(MediaInterface $media) { $source_field = $this->configuration['source_field']; if (empty($source_field)) {