Commit 52eb9366 authored by alexpott's avatar alexpott

Issue #1069140 by claudiu.cristea: Requirements should be provided by image toolkit.

parent 24c502b0
<?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();
}
}
......@@ -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.
*
......
......@@ -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;
......
......@@ -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}
*/
......
......@@ -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}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment