diff --git a/src/Plugin/MediaEntity/Type/Image.php b/src/Plugin/MediaEntity/Type/Image.php index e2fab5b..f3453b1 100644 --- a/src/Plugin/MediaEntity/Type/Image.php +++ b/src/Plugin/MediaEntity/Type/Image.php @@ -107,47 +107,49 @@ class Image extends MediaTypeBase { // Get the file, image and exif data. /** @var \Drupal\file\FileInterface $file */ $file = $media->{$source_field}->entity; - $image = $this->imageFactory->get($file->getFileUri()); - $uri = $file->getFileUri(); + if ($file) { + $image = $this->imageFactory->get($file->getFileUri()); + $uri = $file->getFileUri(); - // Return the field. - switch ($name) { - case 'mime': - return !$file->filemime->isEmpty() ? $file->getMimeType() : FALSE; + // Return the field. + switch ($name) { + case 'mime': + return !$file->filemime->isEmpty() ? $file->getMimeType() : FALSE; - case 'width': - $width = $image->getWidth(); - return $width ? $width : FALSE; + case 'width': + $width = $image->getWidth(); + return $width ? $width : FALSE; - case 'height': - $height = $image->getHeight(); - return $height ? $height : FALSE; + case 'height': + $height = $image->getHeight(); + return $height ? $height : FALSE; - case 'size': - $size = $file->getSize(); - return $size ? $size : FALSE; - } + case 'size': + $size = $file->getSize(); + return $size ? $size : FALSE; + } - if (!empty($this->configuration['gather_exif']) && function_exists('exif_read_data')) { - switch ($name) { - case 'model': - return $this->getExifField($uri, 'Model'); + if (!empty($this->configuration['gather_exif']) && function_exists('exif_read_data')) { + switch ($name) { + case 'model': + return $this->getExifField($uri, 'Model'); - case 'created': - $date = new DrupalDateTime($this->getExifField($uri, 'DateTimeOriginal')); - return $date->getTimestamp(); + case 'created': + $date = new DrupalDateTime($this->getExifField($uri, 'DateTimeOriginal')); + return $date->getTimestamp(); - case 'iso': - return $this->getExifField($uri, 'ISOSpeedRatings'); + case 'iso': + return $this->getExifField($uri, 'ISOSpeedRatings'); - case 'exposure': - return $this->getExifField($uri, 'ExposureTime'); + case 'exposure': + return $this->getExifField($uri, 'ExposureTime'); - case 'aperture': - return $this->getExifField($uri, 'FNumber'); + case 'aperture': + return $this->getExifField($uri, 'FNumber'); - case 'focal_length': - return $this->getExifField($uri, 'FocalLength'); + case 'focal_length': + return $this->getExifField($uri, 'FocalLength'); + } } }