From 3237440708c56cfd50abe51cbbbd4ba509995db2 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Tue, 13 Aug 2019 07:26:31 +1000
Subject: [PATCH] Issue #2849413 by sam-elayyoub, idebr, tatarbj, B N Pandey,
 annetee, developmenticon, borisson_, Lendude: Class name must be a valid
 object or a string in core/modules/image/src/Entity/ImageStyle.php on line
 174

---
 core/modules/image/src/Entity/ImageStyle.php    |  5 ++++-
 .../tests/src/Kernel/MediaSourceFileTest.php    | 17 +++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/core/modules/image/src/Entity/ImageStyle.php b/core/modules/image/src/Entity/ImageStyle.php
index f043b322689b..015adfa74e23 100644
--- a/core/modules/image/src/Entity/ImageStyle.php
+++ b/core/modules/image/src/Entity/ImageStyle.php
@@ -183,7 +183,10 @@ public function buildUri($uri) {
       // source files not stored in the default scheme.
       if ($source_scheme != $default_scheme) {
         $class = $this->getStreamWrapperManager()->getClass($source_scheme);
-        $is_writable = $class::getType() & StreamWrapperInterface::WRITE;
+        $is_writable = NULL;
+        if ($class) {
+          $is_writable = $class::getType() & StreamWrapperInterface::WRITE;
+        }
 
         // Compute the derivative URI scheme. Derivatives created from writable
         // source stream wrappers will inherit the scheme. Derivatives created
diff --git a/core/modules/media/tests/src/Kernel/MediaSourceFileTest.php b/core/modules/media/tests/src/Kernel/MediaSourceFileTest.php
index c36f2b63975f..973e7522465d 100644
--- a/core/modules/media/tests/src/Kernel/MediaSourceFileTest.php
+++ b/core/modules/media/tests/src/Kernel/MediaSourceFileTest.php
@@ -27,4 +27,21 @@ public function testFileExtensionConstraint() {
     $this->assertCount(0, $result);
   }
 
+  /**
+   * Tests a media file can be deleted.
+   */
+  public function testFileDeletion() {
+    $mediaType = $this->createMediaType('file');
+    $media = $this->generateMedia('test.txt', $mediaType);
+    $media->save();
+
+    $source_field_name = $mediaType->getSource()
+      ->getSourceFieldDefinition($mediaType)
+      ->getName();
+    /** @var \Drupal\file\FileInterface $file */
+    $file = $media->get($source_field_name)->entity;
+    $file->delete();
+    $this->assertEmpty($this->container->get('entity_type.manager')->getStorage('file')->loadByProperties(['filename' => 'test.txt']));
+  }
+
 }
-- 
GitLab