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 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, Entity // 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 @@ class MediaSourceFileTest extends MediaKernelTestBase { $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'])); + } + }