You are here

photoswipe.install in PhotoSwipe 8.2

Install, uninstall and update hooks for Photswipe module.

File

photoswipe.install
View source
<?php

/**
 * @file
 * Install, uninstall and update hooks for Photswipe module.
 */
use Drupal\Component\Utility\Unicode;

/**
 * The minimum PhotoSwipe version we support.
 */
const PHOTOSWIPE_MIN_PLUGIN_VERSION = '4.0.0';

/**
 * Implements hook_requirements().
 */
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;
}

/**
 * Trigger cache clear.
 *
 * Empty update function to trigger cache clear after changing field formatter
 * settings.
 */
function photoswipe_update_7001() {

  // Do nothing.
}

Functions

Namesort descending Description
photoswipe_requirements Implements hook_requirements().
photoswipe_update_7001 Trigger cache clear.

Constants

Namesort descending Description
PHOTOSWIPE_MIN_PLUGIN_VERSION The minimum PhotoSwipe version we support.