You are here

leaflet_markercluster.module in Leaflet Markercluster 8

Same filename and directory in other branches
  1. 7 leaflet_markercluster.module

File

leaflet_markercluster.module
View source
<?php

/**
 * Preprocess the leaflet_map theme function to add
 * the markercluster libraries.
 *
 * @param  [type] &$vars [description]
 * @return [type]        [description]
 */
function leaflet_markercluster_preprocess_leaflet_map(&$vars) {
  $vars['#attached']['library'][] = 'leaflet_markercluster/leaflet-markercluster';
  $vars['#attached']['library'][] = 'leaflet_markercluster/leaflet-markercluster-drupal';
}

/**
 * Implements hook_requirements().
 */
function leaflet_markercluster_requirements($phase) {
  $requirements = array();
  if ($phase != 'runtime') {
    return $requirements;
  }
  $library = Drupal::service('library.discovery')
    ->getLibraryByName('leaflet_markercluster', 'leaflet-markercluster');
  $requirements['leaflet_markercluster'] = array(
    'title' => Drupal::translation()
      ->translate('Leaflet Markercluster library'),
  );
  if (file_exists($library['js'][0]['data'])) {
    $requirements['leaflet_markercluster']['value'] = Drupal::translation()
      ->translate('Leaflet Markercluster @version library installed at @path.', array(
      '@version' => $library['version'],
      '@path' => $library['js'][0]['data'],
    ));
    $requirements['leaflet_markercluster']['severity'] = REQUIREMENT_OK;
  }
  else {
    $requirements['leaflet_markercluster']['value'] = Drupal::translation()
      ->translate('Leaflet Markecluster @version library not found at @path. Please !download it to @directory.', array(
      '@version' => $library['version'],
      '@path' => $library['js'][0]['data'],
      '@directory' => dirname($library['js'][0]['data']),
      '!download' => Drupal::l('download', Drupal\Core\Url::fromUri($library['remote'])),
    ));
    $requirements['leaflet_markercluster']['severity'] = REQUIREMENT_ERROR;
  }
  return $requirements;
}

Functions

Namesort descending Description
leaflet_markercluster_preprocess_leaflet_map Preprocess the leaflet_map theme function to add the markercluster libraries.
leaflet_markercluster_requirements Implements hook_requirements().