You are here

function photoswipe_requirements in PhotoSwipe 8

Same name and namespace in other branches
  1. 8.2 photoswipe.install \photoswipe_requirements()
  2. 6 photoswipe.install \photoswipe_requirements()
  3. 7.2 photoswipe.install \photoswipe_requirements()
  4. 7 photoswipe.install \photoswipe_requirements()
  5. 3.x photoswipe.install \photoswipe_requirements()

Implements hook_requirements().

File

./photoswipe.install, line 13
Install, uninstall and update hooks for Photswipe module.

Code

function photoswipe_requirements($phase) {
  $requirements = [];
  if (\Drupal::moduleHandler()
    ->moduleExists('libraries')) {
    if ($phase == 'runtime') {
      $library = libraries_detect('photoswipe');
      $error_type = isset($library['error']) ? Unicode::ucfirst($library['error']) : '';
      $error_message = isset($library['error message']) ? $library['error message'] : '';
      if (empty($library['installed'])) {
        $requirements['photoswipe_plugin'] = [
          'title' => t('Photoswipe plugin'),
          'value' => t('@e: At least @a', [
            '@e' => $error_type,
            '@a' => PHOTOSWIPE_MIN_PLUGIN_VERSION,
          ]),
          'severity' => REQUIREMENT_ERROR,
          'description' => t('@error You need to download the <a href=":url">Photoswipe plugin</a>, extract the archive and place the photoswipe directory in the %path directory on your server.', [
            '@error' => $error_message,
            ':url' => $library['download url'],
            '%path' => 'libraries',
          ]),
        ];
      }
      elseif (version_compare($library['version'], PHOTOSWIPE_MIN_PLUGIN_VERSION, '>=')) {
        $requirements['photoswipe_plugin'] = [
          'title' => t('Photoswipe plugin'),
          'severity' => REQUIREMENT_OK,
          'value' => $library['version'],
        ];
      }
      else {
        $requirements['photoswipe_plugin'] = [
          'title' => t('Photoswipe plugin'),
          'value' => t('At least @a', [
            '@a' => PHOTOSWIPE_MIN_PLUGIN_VERSION,
          ]),
          'severity' => REQUIREMENT_ERROR,
          'description' => t('You need to download a later version of the <a href=":url">Photoswipe plugin</a> and replace the old version located in the %path directory on your server.', [
            ':url' => $library['download url'],
            '%path' => $library['library path'],
          ]),
        ];
      }
    }
  }
  return $requirements;
}