diff --git a/core/lib/Drupal/Core/Image/ImageFactory.php b/core/lib/Drupal/Core/Image/ImageFactory.php index 48ee02b..27773d8 100644 --- a/core/lib/Drupal/Core/Image/ImageFactory.php +++ b/core/lib/Drupal/Core/Image/ImageFactory.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Image; -use Drupal\Core\ImageToolkit\ImageToolkitException; use Drupal\Core\ImageToolkit\ImageToolkitInterface; /** @@ -20,19 +19,16 @@ class ImageFactory { * * @var \Drupal\Core\ImageToolkit\ImageToolkitInterface */ - protected $toolkit = NULL; + protected $toolkit; /** * Constructs a new ImageFactory object. * - * @param \Drupal\Core\ImageToolkit\ImageToolkitInterface|NULL $toolkit - * The image toolkit to use for this image factory, or NULL if - * no default toolkit is available. + * @param \Drupal\Core\ImageToolkit\ImageToolkitInterface $toolkit + * The image toolkit to use for this image factory. */ - public function __construct($toolkit) { - if ($toolkit && $toolkit instanceof ImageToolkitInterface) { - $this->toolkit = $toolkit; - } + public function __construct(ImageToolkitInterface $toolkit) { + $this->toolkit = $toolkit; } /** @@ -52,8 +48,6 @@ public function setToolkit(ImageToolkitInterface $toolkit) { /** * Constructs a new Image object. * - * Throws an ImageToolkitException if the toolkit is not set. - * * @param string $source * The path to an image file. * @@ -61,9 +55,6 @@ public function setToolkit(ImageToolkitInterface $toolkit) { * The new Image object. */ public function get($source) { - if (!$this->toolkit) { - throw new ImageToolkitException('Images can not be processed because the Image toolkit is missing or not configured properly. Visit the Image toolkit configuration page to correct this.'); - } return new Image($source, $this->toolkit); } diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php index ea6a185..f76acd3 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php @@ -47,6 +47,9 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac /** * Gets the default image toolkit. * + * @throws \Drupal\Core\ImageToolkit\ImageToolkitException + * If the toolkit plugin is not valid. + * * @return \Drupal\Core\ImageToolkit\ImageToolkitInterface * Object of the default toolkit, or NULL on error. */ @@ -55,7 +58,7 @@ public function getDefaultToolkit() { $toolkits = $this->getDefinitions(); if (empty($toolkit_id) || !isset($toolkits[$toolkit_id]) || !class_exists($toolkits[$toolkit_id]['class'])) { - return NULL; + throw new ImageToolkitException('Images can not be processed because the Image toolkit is missing or not configured properly. Visit the Image toolkit configuration page to correct this.'); } return $this->createInstance($toolkit_id); diff --git a/core/modules/image/image.install b/core/modules/image/image.install index 76aa952..ca25ebc 100644 --- a/core/modules/image/image.install +++ b/core/modules/image/image.install @@ -33,22 +33,27 @@ function image_requirements($phase) { return array(); } - $toolkit = \Drupal::service('image.toolkit.manager')->getDefaultToolkit(); - $plugin_definition = $toolkit ? $toolkit->getPluginDefinition() : NULL; + // Get info about the default toolkit. $requirements = array( 'image.toolkit' => array( 'title' => t('Image toolkit'), - 'value' => $toolkit ? $toolkit->getPluginId() : t('None'), - 'description' => $toolkit ? $plugin_definition['title'] : t("No image toolkit is configured on the site. Check PHP installed extensions, or add other contributed toolkits that do not require a PHP extension, and make sure that a valid image toolkit is enabled."), - 'severity' => $toolkit ? REQUIREMENT_INFO : REQUIREMENT_ERROR, ), ); - - // If there no valid active toolkit exit here. - if (!$toolkit) { + try { + $toolkit = \Drupal::service('image.toolkit.manager')->getDefaultToolkit(); + $plugin_definition = $toolkit->getPluginDefinition(); + $requirements['image.toolkit']['value'] = $toolkit->getPluginId(); + $requirements['image.toolkit']['description'] = $plugin_definition['title']; + $requirements['image.toolkit']['severity'] = REQUIREMENT_INFO; + } + catch (\Drupal\Core\ImageToolkit\ImageToolkitException $e) { + $requirements['image.toolkit']['value'] = t('None'); + $requirements['image.toolkit']['description'] = t("No image toolkit is configured on the site. Check PHP installed extensions, or add other contributed toolkits that do not require a PHP extension, and make sure that a valid image toolkit is enabled."); + $requirements['image.toolkit']['severity'] = REQUIREMENT_ERROR; return $requirements; } + // Get requirements provided by the toolkit. foreach ($toolkit->requirements() as $key => $requirement) { $namespaced_key = 'image.toolkit.' . $toolkit->getPluginId() . '.' . $key; $requirements[$namespaced_key] = $requirement;