use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
-use Drupal\file\Entity\File;
+use Drupal\file\FileInterface;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\field\FieldConfigInterface;
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;
* 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;
* 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;
* 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);
* 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);
'image_crop_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
+ 'image_scale_and_crop_summary' => [
+ 'variables' => ['data' => NULL, 'effect' => []],
+ ],
'image_rotate_summary' => [
'variables' => ['data' => NULL, 'effect' => []],
],
/**
* Implements hook_file_move().
*/
-function image_file_move(File $file, File $source) {
+function image_file_move(FileInterface $file, FileInterface $source) {
// Delete any image derivatives at the original image path.
image_path_flush($source->getFileUri());
}
/**
* Implements hook_ENTITY_TYPE_predelete() for file entities.
*/
-function image_file_predelete(File $file) {
+function image_file_predelete(FileInterface $file) {
// Delete any image derivatives of this image.
image_path_flush($file->getFileUri());
}
'#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'];
}
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());
}
}
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());
}
}