You are here

leaflet.install in Leaflet 2.0.x

Same filename and directory in other branches
  1. 8 leaflet.install
  2. 7 leaflet.install
  3. 2.1.x leaflet.install

Contains the leaflet.install file.

File

leaflet.install
View source
<?php

/**
 * @file
 * Contains the leaflet.install file.
 */
use Drupal\Core\Url;
use Drupal\Core\Link;

/**
 * Implements hook_requirements().
 */
function leaflet_requirements($phase) {
  $requirements = [];
  if ($phase != 'runtime') {
    return $requirements;
  }
  $library = \Drupal::service('library.discovery')
    ->getLibraryByName('leaflet', 'leaflet');
  $requirements['leaflet'] = [
    'title' => \Drupal::translation()
      ->translate('Leaflet library'),
  ];
  $maps_info = \Drupal::translation()
    ->translate('@maps available.', [
    '@maps' => \Drupal::translation()
      ->formatPlural(count(leaflet_map_get_info()), 'One map', '@count maps'),
  ]);

  // Check the defined type of the leaflet.js file; if it is external then
  // assume that we are using a CDN version.
  if ($library['js'][0]['type'] == 'external') {
    $requirements['leaflet']['value'] = \Drupal::translation()
      ->translate('Using CDN version @version.', [
      '@version' => $library['version'],
    ]) . ' ' . $maps_info;
  }
  else {
    if (file_exists($library['js'][0]['data'])) {
      $requirements['leaflet']['value'] = \Drupal::translation()
        ->translate('Leaflet @version library installed at @path.', [
        '@version' => $library['version'],
        '@path' => $library['js'][0]['data'],
      ]) . ' ' . $maps_info;
      $requirements['leaflet']['severity'] = REQUIREMENT_OK;
    }
    else {
      $requirements['leaflet']['value'] = \Drupal::translation()
        ->translate('Leaflet @version library not found at @path. Please !download it to @directory, or undo your changes to the libraries registry to use the CDN version.', [
        '@version' => $library['version'],
        '@path' => $library['js'][0]['data'],
        '@directory' => dirname($library['js'][0]['data']),
        '!download' => Link::fromTextAndUrl('download', Url::fromUri($library['remote'])),
      ]);
      $requirements['leaflet']['severity'] = REQUIREMENT_ERROR;
    }
  }
  return $requirements;
}

Functions

Namesort descending Description
leaflet_requirements Implements hook_requirements().