diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index eaef644..db2552b 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -5,7 +5,6 @@ * Contains Drupal. */ -use Drupal\system\Plugin\ImageToolkitInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -392,18 +391,4 @@ public static function languageManager() { return static::$container->get('language_manager'); } - /** - * @param string $source - * @param \Drupal\system\Plugin\ImageToolkitInterface $toolkit - * - * @return \Drupal\Core\Image\ImageInterface - */ - public static function image($source, ImageToolkitInterface $toolkit = NULL) { - $factory = static::$container->get('image.factory'); - if ($toolkit) { - $factory->setToolkit($toolkit); - } - return $factory->get($source); - } - } diff --git a/core/lib/Drupal/Core/Image/ImageFactory.php b/core/lib/Drupal/Core/Image/ImageFactory.php index 06d827e..91b28d2 100644 --- a/core/lib/Drupal/Core/Image/ImageFactory.php +++ b/core/lib/Drupal/Core/Image/ImageFactory.php @@ -20,19 +20,20 @@ class ImageFactory { protected $toolkit; /** - * @todo. + * Constructs a new ImageFactory object. * * @param \Drupal\system\Plugin\ImageToolkitInterface $toolkit + * The image toolkit to use for this image factory. */ public function __construct(ImageToolkitInterface $toolkit) { - $this->setToolkit($toolkit); + $this->toolkit = $toolkit; } /** * Sets a custom image toolkit. * * @param \Drupal\system\Plugin\ImageToolkitInterface $toolkit - * The image toolkit to use for this image. + * The image toolkit to use for this image factory. * * @return self * Returns this image. diff --git a/core/modules/file/file.module b/core/modules/file/file.module index c8bbd3f..66e81af 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -420,7 +420,7 @@ function file_validate_size(File $file, $file_limit = 0, $user_limit = 0) { function file_validate_is_image(File $file) { $errors = array(); - $image = Drupal::image($file->getFileUri()); + $image = Drupal::service('image.factory')->get($file->getFileUri()); if (!$image->getExtension()) { $errors[] = t('Only JPEG, PNG and GIF images are allowed.'); } @@ -455,14 +455,15 @@ function file_validate_image_resolution(File $file, $maximum_dimensions = 0, $mi $errors = array(); // Check first that the file is an image. - $image = Drupal::image($file->getFileUri()); + $image_factory = Drupal::service('image.factory'); + $image = $image_factory->get($file->getFileUri()); if ($image->getExtension()) { if ($maximum_dimensions) { // Check that it is smaller than the given dimensions. list($width, $height) = explode('x', $maximum_dimensions); if ($image->getWidth() > $width || $image->getHeight() > $height) { // Try to resize the image to fit the dimensions. - $image = Drupal::image($file->getFileUri()); + $image = $image_factory->get($file->getFileUri()); if ($image->getResource()) { $image->scale($width, $height); $image->save(); diff --git a/core/modules/image/image.admin.inc b/core/modules/image/image.admin.inc index 0a53fcc..0eb33c6 100644 --- a/core/modules/image/image.admin.inc +++ b/core/modules/image/image.admin.inc @@ -379,7 +379,8 @@ function theme_image_style_preview($variables) { // Set up original file information. $original_path = $sample_image; - $original_image = Drupal::image($original_path); + $image_factory = Drupal::service('image.factory'); + $original_image = $image_factory->get($original_path); $original_image = array( 'width' => $original_image->getWidth(), 'height' => $original_image->getHeight(), @@ -399,7 +400,7 @@ function theme_image_style_preview($variables) { if (!file_exists($preview_file)) { $style->createDerivative($original_path, $preview_file); } - $preview_image = Drupal::image($preview_file); + $preview_image = $image_factory->get($preview_file); $preview_image = array( 'width' => $preview_image->getWidth(), 'height' => $preview_image->getHeight(), diff --git a/core/modules/image/image.field.inc b/core/modules/image/image.field.inc index c8bbedc..11a2fd1 100644 --- a/core/modules/image/image.field.inc +++ b/core/modules/image/image.field.inc @@ -226,10 +226,11 @@ function _image_field_resolution_validate($element, &$form_state) { * Implements hook_field_presave(). */ function image_field_presave(EntityInterface $entity, $field, $instance, $langcode, &$items) { + $image_factory = Drupal::service('image.factory'); // Determine the dimensions if necessary. foreach ($items as &$item) { if (!isset($item['width']) || !isset($item['height'])) { - $image = Drupal::image(file_load($item['target_id'])->getFileUri()); + $image = $image_factory->get(file_load($item['target_id'])->getFileUri()); if ($image->getExtension()) { $item['width'] = $image->getWidth(); $item['height'] = $image->getHeight(); @@ -299,7 +300,7 @@ function image_field_widget_process($element, &$form_state, $form) { $variables['height'] = $element['#value']['height']; } else { - $image = Drupal::image($file->getFileUri()); + $image = Drupal::service('image.factory')->get($file->getFileUri()); if ($image->getExtension()) { $variables['width'] = $image->getWidth(); $variables['height'] = $image->getHeight(); diff --git a/core/modules/image/image.module b/core/modules/image/image.module index bbab24a..7def491 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -275,7 +275,7 @@ function image_file_download($uri) { $original_uri = file_uri_scheme($uri) . '://' . implode('/', $args); // Check that the file exists and is an image. - $image = Drupal::image($uri); + $image = Drupal::service('image.factory')->get($uri); if ($image->getExtension()) { // Check the permissions of the original to grant access to this image. $headers = module_invoke_all('file_download', $original_uri); diff --git a/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php b/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php index 2e446ab..97f23de 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php +++ b/core/modules/image/lib/Drupal/image/Plugin/Core/Entity/ImageStyle.php @@ -277,7 +277,7 @@ public function createDerivative($original_uri, $derivative_uri) { return FALSE; } - $image = \Drupal::image($original_uri); + $image = \Drupal::service('image.factory')->get($original_uri); if (!$image->getResource()) { return FALSE; } diff --git a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleImageEffect.php b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleImageEffect.php index 6f0aacd..1c314b2 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleImageEffect.php +++ b/core/modules/image/lib/Drupal/image/Plugin/ImageEffect/ScaleImageEffect.php @@ -8,6 +8,7 @@ namespace Drupal\image\Plugin\ImageEffect; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Image\Image; use Drupal\Core\Image\ImageInterface; use Drupal\image\Annotation\ImageEffect; diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index aac38bb..7d1a954 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -2149,7 +2149,7 @@ function hook_file_download($uri) { return -1; } else { - $image = Drupal::image($uri); + $image = Drupal::service('image.factory')->get($uri); return array('Content-Type' => $image->getMimeType()); } } diff --git a/core/tests/Drupal/Tests/Component/Image/ImageTest.php b/core/tests/Drupal/Tests/Component/Image/ImageTest.php index 760ab09..a26d440 100644 --- a/core/tests/Drupal/Tests/Component/Image/ImageTest.php +++ b/core/tests/Drupal/Tests/Component/Image/ImageTest.php @@ -58,7 +58,7 @@ function testScaleDimensions($input, $output) { */ public function providerTestScaleDimensions() { // Define input / output datasets to test different branch conditions. - $test = array(); + $tests = array(); // Test branch conditions: // - No height.