You are here

public function ImagemagickToolkit::getRequirements in ImageMagick 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/ImageToolkit/ImagemagickToolkit.php \Drupal\imagemagick\Plugin\ImageToolkit\ImagemagickToolkit::getRequirements()
  2. 8 src/Plugin/ImageToolkit/ImagemagickToolkit.php \Drupal\imagemagick\Plugin\ImageToolkit\ImagemagickToolkit::getRequirements()

Gets toolkit requirements in a format suitable for hook_requirements().

Return value

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.

Overrides ImageToolkitBase::getRequirements

See also

hook_requirements()

File

src/Plugin/ImageToolkit/ImagemagickToolkit.php, line 1357

Class

ImagemagickToolkit
Provides ImageMagick integration toolkit for image manipulation.

Namespace

Drupal\imagemagick\Plugin\ImageToolkit

Code

public function getRequirements() {
  $reported_info = [];
  if (stripos(ini_get('disable_functions'), 'proc_open') !== FALSE) {

    // proc_open() is disabled.
    $severity = REQUIREMENT_ERROR;
    $reported_info[] = $this
      ->t("The <a href=':proc_open_url'>proc_open()</a> PHP function is disabled. It must be enabled for the toolkit to work. Edit the <a href=':disable_functions_url'>disable_functions</a> entry in your php.ini file, or consult your hosting provider.", [
      ':proc_open_url' => 'http://php.net/manual/en/function.proc-open.php',
      ':disable_functions_url' => 'http://php.net/manual/en/ini.core.php#ini.disable-functions',
    ]);
  }
  else {
    $status = $this
      ->getExecManager()
      ->checkPath($this->configFactory
      ->get('imagemagick.settings')
      ->get('path_to_binaries'));
    if (!empty($status['errors'])) {

      // Can not execute 'convert'.
      $severity = REQUIREMENT_ERROR;
      foreach ($status['errors'] as $error) {
        $reported_info[] = $error;
      }
      $reported_info[] = $this
        ->t('Go to the <a href=":url">Image toolkit</a> page to configure the toolkit.', [
        ':url' => Url::fromRoute('system.image_toolkit_settings')
          ->toString(),
      ]);
    }
    else {

      // No errors, report the version information.
      $severity = REQUIREMENT_INFO;
      $version_info = explode("\n", preg_replace('/\\r/', '', Html::escape($status['output'])));
      $value = array_shift($version_info);
      $more_info_available = FALSE;
      foreach ($version_info as $key => $item) {
        if (stripos($item, 'feature') !== FALSE || $key > 3) {
          $more_info_available = TRUE;
          break;
        }
        $reported_info[] = $item;
      }
      if ($more_info_available) {
        $reported_info[] = $this
          ->t('To display more information, go to the <a href=":url">Image toolkit</a> page, and expand the \'Version information\' section.', [
          ':url' => Url::fromRoute('system.image_toolkit_settings')
            ->toString(),
        ]);
      }
      $reported_info[] = '';
      $reported_info[] = $this
        ->t("Enabled image file extensions: %extensions", [
        '%extensions' => Unicode::strtolower(implode(', ', static::getSupportedExtensions())),
      ]);
    }
  }
  $requirements = [
    'imagemagick' => [
      'title' => $this
        ->t('ImageMagick'),
      'value' => isset($value) ? $value : NULL,
      'description' => [
        '#markup' => implode('<br />', $reported_info),
      ],
      'severity' => $severity,
    ],
  ];

  // Warn if parsing via 'getimagesize'.
  // @todo remove in 8.x-3.0.
  if ($this->configFactory
    ->getEditable('imagemagick.settings')
    ->get('use_identify') === FALSE) {
    $requirements['imagemagick_getimagesize'] = [
      'title' => $this
        ->t('ImageMagick'),
      'value' => $this
        ->t('Use "identify" to parse image files'),
      'description' => $this
        ->t('The toolkit is set to use the <kbd>getimagesize</kbd> PHP function to parse image files. This functionality will be dropped in the next major release of the Imagemagick module. Go to the <a href=":url">Image toolkit</a> settings page, and ensure that the \'Use "identify"\' flag in the \'Execution options\' tab is selected.', [
        ':url' => Url::fromRoute('system.image_toolkit_settings')
          ->toString(),
      ]),
      'severity' => REQUIREMENT_WARNING,
    ];
  }
  return $requirements;
}