diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitBase.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitBase.php new file mode 100644 index 0000000000000000000000000000000000000000..4f28a6eab1dd8f9a3697139588a714be4d0ddcf3 --- /dev/null +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitBase.php @@ -0,0 +1,21 @@ +<?php + +/** + * @file + * Contains \Drupal\Core\ImageToolkit\ImageToolkitBase. + */ + +namespace Drupal\Core\ImageToolkit; + +use Drupal\Core\Plugin\PluginBase; + +abstract class ImageToolkitBase extends PluginBase implements ImageToolkitInterface { + + /** + * {@inheritdoc} + */ + public function getRequirements() { + return array(); + } + +} diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitInterface.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitInterface.php index 351d6d6fd4e3797f230b28f8ccab5e15a1dd139e..a5f96f3d06279053e334d93c4c530add200d3a75 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitInterface.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitInterface.php @@ -216,6 +216,20 @@ public function scaleAndCrop(ImageInterface $image, $width, $height); */ public function getInfo(ImageInterface $image); + /** + * Gets toolkit requirements in a format suitable for hook_requirements(). + * + * @return array + * An associative requirements array as is returned by hook_requirements(). + * If the toolkit claims no requirements to the system, returns an empty + * array. The array can have arbitrary keys and they do not have to be + * prefixed by e.g. the module name or toolkit ID, as the system will make + * the keys globally unique. + * + * @see hook_requirements() + */ + public function getRequirements(); + /** * Verifies Image Toolkit is set up correctly. * diff --git a/core/modules/image/image.install b/core/modules/image/image.install index c48a834e774866a489b197086afad3ec1b478fc4..6a59953667f79b128dfb1605ef7a36210d8e8f0c 100644 --- a/core/modules/image/image.install +++ b/core/modules/image/image.install @@ -29,30 +29,35 @@ function image_uninstall() { * @param $phase */ function image_requirements($phase) { - $requirements = array(); + if ($phase != 'runtime') { + return array(); + } - if ($phase == 'runtime') { - // Check for the PHP GD library. - if (function_exists('imagegd2')) { - $info = gd_info(); - $requirements['image_gd'] = array( - 'value' => $info['GD Version'], - ); + $toolkit = \Drupal::service('image.toolkit.manager')->getDefaultToolkit(); + if ($toolkit) { + $plugin_definition = $toolkit->getPluginDefinition(); + $requirements = array( + 'image.toolkit' => array( + 'title' => t('Image toolkit'), + 'value' => $toolkit->getPluginId(), + 'description' => $plugin_definition['title'], + ), + ); - // Check for filter and rotate support. - if (!function_exists('imagefilter') || !function_exists('imagerotate')) { - $requirements['image_gd']['severity'] = REQUIREMENT_WARNING; - $requirements['image_gd']['description'] = t('The GD Library for PHP is enabled, but was compiled without support for functions used by the rotate and desaturate effects. It was probably compiled using the official GD libraries from http://www.libgd.org instead of the GD library bundled with PHP. You should recompile PHP --with-gd using the bundled GD library. See <a href="@url">the PHP manual</a>.', array('@url' => 'http://www.php.net/manual/book.image.php')); - } + foreach ($toolkit->getRequirements() as $key => $requirement) { + $namespaced_key = 'image.toolkit.' . $toolkit->getPluginId() . '.' . $key; + $requirements[$namespaced_key] = $requirement; } - else { - $requirements['image_gd'] = array( - 'value' => t('Not installed'), + } + else { + $requirements = array( + 'image.toolkit' => array( + 'title' => t('Image toolkit'), + 'value' => t('None'), + 'description' => t("No image toolkit is configured on the site. Check PHP installed extensions or add a contributed toolkit that doesn't require a PHP extension. Make sure that at least one valid image toolkit is enabled."), 'severity' => REQUIREMENT_ERROR, - 'description' => t('The GD library for PHP is missing or outdated. Check the <a href="@url">PHP image documentation</a> for information on how to correct this.', array('@url' => 'http://www.php.net/manual/book.image.php')), - ); - } - $requirements['image_gd']['title'] = t('GD library rotate and desaturate effects'); + ), + ); } return $requirements; diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php index 5499c945177f6ca63abd6ee95eaa6e1dba337c2b..e5c55286868fd11540c4ba304c4366e538f19d32 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php @@ -7,9 +7,8 @@ namespace Drupal\system\Plugin\ImageToolkit; -use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Image\ImageInterface; -use Drupal\Core\ImageToolkit\ImageToolkitInterface; +use Drupal\Core\ImageToolkit\ImageToolkitBase; use Drupal\Component\Utility\Image as ImageUtility; /** @@ -20,7 +19,7 @@ * title = @Translation("GD2 image manipulation toolkit") * ) */ -class GDToolkit extends PluginBase implements ImageToolkitInterface { +class GDToolkit extends ImageToolkitBase { /** * {@inheritdoc} @@ -322,6 +321,27 @@ public function createTmp(ImageInterface $image, $width, $height) { return $res; } + /** + * {@inheritdoc} + */ + public function getRequirements() { + $requirements = array(); + + $info = gd_info(); + $requirements['version'] = array( + 'title' => t('GD library'), + 'value' => $info['GD Version'], + ); + + // Check for filter and rotate support. + if (!function_exists('imagefilter') || !function_exists('imagerotate')) { + $requirements['version']['severity'] = REQUIREMENT_WARNING; + $requirements['version']['description'] = t('The GD Library for PHP is enabled, but was compiled without support for functions used by the rotate and desaturate effects. It was probably compiled using the official GD libraries from http://www.libgd.org instead of the GD library bundled with PHP. You should recompile PHP --with-gd using the bundled GD library. See <a href="@url">the PHP manual</a>.', array('@url' => 'http://www.php.net/manual/book.image.php')); + } + + return $requirements; + } + /** * {@inheritdoc} */ diff --git a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php index 15040a8c59f51e281c4472d43464156a4dffb4ec..d677d139aea3eea3328ed04c98dd225ed7c50d3e 100644 --- a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php @@ -7,9 +7,8 @@ namespace Drupal\image_test\Plugin\ImageToolkit; -use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Image\ImageInterface; -use Drupal\Core\ImageToolkit\ImageToolkitInterface; +use Drupal\Core\ImageToolkit\ImageToolkitBase; /** * Defines a Test toolkit for image manipulation within Drupal. @@ -19,7 +18,7 @@ * title = @Translation("A dummy toolkit that works") * ) */ -class TestToolkit extends PluginBase implements ImageToolkitInterface { +class TestToolkit extends ImageToolkitBase { /** * {@inheritdoc}