Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / image / src / Entity / ImageStyle.php
index fb096a7fdb295226b7cd06d7fd7517a96d633ccf..dd261248a78fe171d5513cc06229a9bcba694635 100644 (file)
@@ -14,9 +14,11 @@ use Drupal\image\ImageEffectInterface;
 use Drupal\image\ImageStyleInterface;
 use Drupal\Component\Utility\Crypt;
 use Drupal\Component\Utility\UrlHelper;
+use Drupal\Component\Utility\Unicode;
 use Drupal\Core\StreamWrapper\StreamWrapperInterface;
 use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
 use Drupal\Core\Entity\Entity\EntityViewDisplay;
+
 /**
  * Defines an image style configuration entity.
  *
@@ -274,9 +276,8 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, Entity
    * {@inheritdoc}
    */
   public function createDerivative($original_uri, $derivative_uri) {
-
     // If the source file doesn't exist, return FALSE without creating folders.
-    $image = \Drupal::service('image.factory')->get($original_uri);
+    $image = $this->getImageFactory()->get($original_uri);
     if (!$image->isValid()) {
       return FALSE;
     }
@@ -340,6 +341,18 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, Entity
     return $this;
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function supportsUri($uri) {
+    // Only support the URI if its extension is supported by the current image
+    // toolkit.
+    return in_array(
+      Unicode::strtolower(pathinfo($uri, PATHINFO_EXTENSION)),
+      $this->getImageFactory()->getSupportedExtensions()
+    );
+  }
+
   /**
    * {@inheritdoc}
    */
@@ -408,6 +421,16 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, Entity
     return \Drupal::service('plugin.manager.image.effect');
   }
 
+  /**
+   * Returns the image factory.
+   *
+   * @return \Drupal\Core\Image\ImageFactory
+   *   The image factory.
+   */
+  protected function getImageFactory() {
+    return \Drupal::service('image.factory');
+  }
+
   /**
    * Gets the Drupal private key.
    *