Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / image / image.module
index 6107ecd909ec81a108ef25f0bf253cae5eba369d..30358b90652cc207f6ff8e0e7224b9f67c10bb61 100644 (file)
@@ -16,6 +16,8 @@ use Drupal\image\Entity\ImageStyle;
  * Image style constant for user presets in the database.
  *
  * @deprecated in Drupal 8.1.x, will be removed before Drupal 9.0.0.
+ *
+ * @see https://www.drupal.org/node/1820974
  */
 const IMAGE_STORAGE_NORMAL = 1;
 
@@ -23,6 +25,8 @@ const IMAGE_STORAGE_NORMAL = 1;
  * Image style constant for user presets that override module-defined presets.
  *
  * @deprecated in Drupal 8.1.x, will be removed before Drupal 9.0.0.
+ *
+ * @see https://www.drupal.org/node/1820974
  */
 const IMAGE_STORAGE_OVERRIDE = 2;
 
@@ -30,6 +34,8 @@ const IMAGE_STORAGE_OVERRIDE = 2;
  * Image style constant for module-defined presets in code.
  *
  * @deprecated in Drupal 8.1.x, will be removed before Drupal 9.0.0.
+ *
+ * @see https://www.drupal.org/node/1820974
  */
 const IMAGE_STORAGE_DEFAULT = 4;
 
@@ -37,6 +43,8 @@ const IMAGE_STORAGE_DEFAULT = 4;
  * Image style constant to represent an editable preset.
  *
  * @deprecated in Drupal 8.1.x, will be removed before Drupal 9.0.0.
+ *
+ * @see https://www.drupal.org/node/1820974
  */
 define('IMAGE_STORAGE_EDITABLE', IMAGE_STORAGE_NORMAL | IMAGE_STORAGE_OVERRIDE);
 
@@ -44,6 +52,8 @@ define('IMAGE_STORAGE_EDITABLE', IMAGE_STORAGE_NORMAL | IMAGE_STORAGE_OVERRIDE);
  * Image style constant to represent any module-based preset.
  *
  * @deprecated in Drupal 8.1.x, will be removed before Drupal 9.0.0.
+ *
+ * @see https://www.drupal.org/node/1820974
  */
 define('IMAGE_STORAGE_MODULE', IMAGE_STORAGE_OVERRIDE | IMAGE_STORAGE_DEFAULT);
 
@@ -292,10 +302,28 @@ function template_preprocess_image_style(&$variables) {
     '#width' => $dimensions['width'],
     '#height' => $dimensions['height'],
     '#attributes' => $variables['attributes'],
-    '#uri' => $style->buildUrl($variables['uri']),
     '#style_name' => $variables['style_name'],
   ];
 
+  // If the current image toolkit supports this file type, prepare the URI for
+  // the derivative image. If not, just use the original image resized to the
+  // dimensions specified by the style.
+  if ($style->supportsUri($variables['uri'])) {
+    $variables['image']['#uri'] = $style->buildUrl($variables['uri']);
+  }
+  else {
+    $variables['image']['#uri'] = $variables['uri'];
+    // Don't render the image by default, but allow other preprocess functions
+    // to override that if they need to.
+    $variables['image']['#access'] = FALSE;
+
+    // Inform the site builders why their image didn't work.
+    \Drupal::logger('image')->warning('Could not apply @style image style to @uri because the style does not support it.', [
+      '@style' => $style->label(),
+      '@uri' => $variables['uri'],
+    ]);
+  }
+
   if (isset($variables['alt']) || array_key_exists('alt', $variables)) {
     $variables['image']['#alt'] = $variables['alt'];
   }
@@ -404,7 +432,7 @@ function image_field_storage_config_update(FieldStorageConfigInterface $field_st
   if ($file_new && (file_uri_scheme($file_new->getFileUri()) != $field_storage->getSetting('uri_scheme'))) {
     $directory = $field_storage->getSetting('uri_scheme') . '://default_images/';
     file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
-    file_move($file_new, $directory . $file_new->filename);
+    file_move($file_new, $directory . $file_new->getFilename());
   }
 }
 
@@ -442,7 +470,7 @@ function image_field_config_update(FieldConfigInterface $field) {
   if ($file_new && (file_uri_scheme($file_new->getFileUri()) != $field_storage->getSetting('uri_scheme'))) {
     $directory = $field_storage->getSetting('uri_scheme') . '://default_images/';
     file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
-    file_move($file_new, $directory . $file_new->filename);
+    file_move($file_new, $directory . $file_new->getFilename());
   }
 }