diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitInterface.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitInterface.php index 214923f..0ac928b 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitInterface.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitInterface.php @@ -174,26 +174,22 @@ public function save(ImageInterface $image, $destination); public function getInfo(ImageInterface $image); /** - * Gets toolkit requirements in a format suitable for hook_requirements(). + * Verifies if the image toolkit is set up correctly. * - * @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 requirements(); - - /** - * Verifies Image Toolkit is set up correctly. + * @param array $requirements + * An associative requirements array passed by reference in the same format + * as is returned by hook_requirements(). If the toolkit claims no + * requirements to the system, no items will be added to this array. The + * method can add new items with arbitrary keys. Those keys do not have to + * be prefixed by e.g. the module name or toolkit ID, as the system will + * make the keys globally unique. * * @return bool - * True if the GD toolkit is available on this machine. + * TRUE if the toolkit is available on this machine. + * + * @see hook_requirements() */ - public static function isAvailable(); + public static function availability(array &$requirements = array()); /** * Returns a list of image types supported by the toolkit. diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php index 43686ff..3c53344 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitManager.php @@ -84,7 +84,7 @@ public function getAvailableToolkits() { $output = array(); foreach ($toolkits as $id => $definition) { // Only allow modules that aren't marked as unavailable. - if (call_user_func($definition['class'] . '::isAvailable')) { + if (call_user_func($definition['class'] . '::availability')) { $output[$id] = $definition; } } diff --git a/core/modules/image/image.install b/core/modules/image/image.install index 2ef40a2..4dba3b9 100644 --- a/core/modules/image/image.install +++ b/core/modules/image/image.install @@ -33,11 +33,13 @@ function image_requirements($phase) { return array(); } - $toolkit = \Drupal::service('image.toolkit.manager')->getDefaultToolkit(); $requirements = array(); - foreach ($toolkit->requirements() as $key => $requirement) { + $toolkit = \Drupal::service('image.toolkit.manager')->getDefaultToolkit(); + $toolkit->availability($requirements); + foreach ($requirements as $key => $requirement) { $namespaced_key = 'image.toolkit.' . $toolkit->getPluginId() . '.' . $key; $requirements[$namespaced_key] = $requirement; + unset($requirements[$key]); } 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 810c16d..22bda91 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkit/GDToolkit.php @@ -275,10 +275,15 @@ public function createTmp(ImageInterface $image, $width, $height) { /** * {@inheritdoc} */ - public function requirements() { - $requirements = array(); + public static function availability(array &$requirements = array()) { + if ($check = get_extension_funcs('gd')) { + $available = in_array('imagegd2', $check); + } + else { + $available = FALSE; + } - if (static::isAvailable()) { + if ($available) { $info = gd_info(); $requirements['rotate_desaturate'] = array( 'value' => $info['GD Version'], @@ -299,20 +304,7 @@ public function requirements() { } $requirements['rotate_desaturate']['title'] = t('GD library rotate and desaturate effects'); - return $requirements; - } - - /** - * {@inheritdoc} - */ - public static function isAvailable() { - if ($check = get_extension_funcs('gd')) { - if (in_array('imagegd2', $check)) { - // GD2 support is available. - return TRUE; - } - } - return FALSE; + return $available; } /** diff --git a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/BrokenToolkit.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/BrokenToolkit.php index e5ead27..ae6d64d 100644 --- a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/BrokenToolkit.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/BrokenToolkit.php @@ -20,7 +20,7 @@ class BrokenToolkit extends TestToolkit { /** * {@inheritdoc} */ - public static function isAvailable() { + public static function availability(array &$requirements = array()) { return FALSE; } } 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 d2fcdef..88c1731 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 @@ -126,14 +126,7 @@ protected function logCall($op, $args) { /** * {@inheritdoc} */ - public function requirements() { - return array(); - } - - /** - * {@inheritdoc} - */ - public static function isAvailable() { + public static function availability(array &$requirements = array()) { return TRUE; }