diff --git a/core/lib/Drupal/Core/Image/Image.php b/core/lib/Drupal/Core/Image/Image.php index 402243f..37a4fa8 100644 --- a/core/lib/Drupal/Core/Image/Image.php +++ b/core/lib/Drupal/Core/Image/Image.php @@ -71,15 +71,15 @@ class Image implements ImageInterface { /** * Constructs a new Image object. * - * @param string|NULL $source - * The path to an image file, or NULL to construct the object with no - * image source. + * @param string $source + * The path to an image file, or an empty string to construct the object + * with no image source. * @param \Drupal\Core\ImageToolkit\ImageToolkitInterface $toolkit * The image toolkit. */ public function __construct($source, ImageToolkitInterface $toolkit) { $this->toolkit = $toolkit; - if ($source) { + if (!empty($source)) { $this->source = $source; $this->processInfo(); } diff --git a/core/lib/Drupal/Core/Image/ImageFactory.php b/core/lib/Drupal/Core/Image/ImageFactory.php index 3bff021..a7098a0 100644 --- a/core/lib/Drupal/Core/Image/ImageFactory.php +++ b/core/lib/Drupal/Core/Image/ImageFactory.php @@ -36,6 +36,7 @@ class ImageFactory { */ public function __construct(ImageToolkitManager $toolkit_manager) { $this->toolkitManager = $toolkit_manager; + $this->toolkitId = $this->toolkitManager->getDefaultToolkitId(); } /** @@ -59,43 +60,33 @@ public function setToolkitId($toolkit_id) { * The ID of the image toolkit in use by the image factory. */ public function getToolkitId() { - return $this->resolveToolkitId(); + return $this->toolkitId; } /** * Constructs a new Image object. * - * @param string|NULL $source - * The path to an image file, or NULL to construct the object with no - * image source. + * Normally, the toolkit set as default in the admin UI is used by the + * factory to create new Image objects. This can be overridden through + * \Drupal\Core\Image\ImageInterface::setToolkitId() so that any new Image + * object created will use the new toolkit specified. Finally, a single + * Image object can be created using a specific toolkit, regardless of the + * current factory settings, by passing its plugin ID in the $toolkit_id + * argument. + * + * @param string $source + * The path to an image file, or an empty string to construct the object + * with no image source. * @param string $toolkit_id * (Optional) The image toolkit ID to use for this image. * * @return \Drupal\Core\Image\ImageInterface * An Image object. + * + * @see ImageFactory::setToolkitId() */ public function get($source, $toolkit_id = NULL) { - $toolkit_id = $this->resolveToolkitId($toolkit_id); + $toolkit_id = $toolkit_id ?: $this->toolkitId; return new Image($source, $this->toolkitManager->createInstance($toolkit_id)); } - - /** - * Resolves a toolkit ID. - * - * @param string $toolkit_id - * (Optional) An image toolkit ID. If not specified, the toolkit currently - * set will be returned, or the default one if no toolkit is set. - * - * @return string - * An image toolkit ID. - */ - protected function resolveToolkitId($toolkit_id = NULL) { - if (!$toolkit_id) { - if (!$this->toolkitId) { - $this->toolkitId = $this->toolkitManager->getDefaultToolkitId(); - } - $toolkit_id = $this->toolkitId; - } - return $toolkit_id; - } }