Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / image / src / Plugin / Field / FieldType / ImageItem.php
index 7b8b27521650e6f2db3231d1a8ec7a74ce495d3e..9e58ccd70dbcb46d0b07899661d4629efa3aa0ee 100644 (file)
@@ -3,6 +3,7 @@
 namespace Drupal\image\Plugin\Field\FieldType;
 
 use Drupal\Component\Utility\Random;
+use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Field\FieldDefinitionInterface;
 use Drupal\Core\Field\FieldStorageDefinitionInterface;
 use Drupal\Core\Form\FormStateInterface;
@@ -313,13 +314,18 @@ class ImageItem extends FileItem {
     $height = $this->height;
 
     // Determine the dimensions if necessary.
-    if (empty($width) || empty($height)) {
-      $image = \Drupal::service('image.factory')->get($this->entity->getFileUri());
-      if ($image->isValid()) {
-        $this->width = $image->getWidth();
-        $this->height = $image->getHeight();
+    if ($this->entity && $this->entity instanceof EntityInterface) {
+      if (empty($width) || empty($height)) {
+        $image = \Drupal::service('image.factory')->get($this->entity->getFileUri());
+        if ($image->isValid()) {
+          $this->width = $image->getWidth();
+          $this->height = $image->getHeight();
+        }
       }
     }
+    else {
+      trigger_error(sprintf("Missing file with ID %s.", $this->target_id), E_USER_WARNING);
+    }
   }
 
   /**