openlayers-8.x-4.x-dev/openlayers.module

openlayers.module
<?php

/**
 * @file
 * Contains the openlayers.module file.
 */

/**
 * Implements hook_theme().
 */
function openlayers_theme() {
  return [
    'openlayers_map' => [
      'variables' => [
        'map_id' => NULL,
        'height' => '400px',
        'map' => [],
      ],
    ],
  ];
}

/**
 * Add dynamic library definitions.
 *
 * Modules may implement this hook to add dynamic library definitions. Static
 * libraries, which do not depend on any runtime information, should be declared
 * in a modulename.libraries.yml file instead.
 *
 * @return array[]
 *   An array of library definitions to register, keyed by library ID. The
 *   library ID will be prefixed with the module name automatically.
 *
 * @see core.libraries.yml
 * @see hook_library_info_alter()
 */
function openlayers_library_info_build() {

  global $base_url;
  $libraries = [];

  $js_css_group = 'openlayers';

  $libraryPath = DRUPAL_ROOT . '/libraries/openlayers';
  if (file_exists($libraryPath) && is_dir($libraryPath)) {
    $versions = scandir($libraryPath . '/versions');
    $local_variants = [];
    foreach ($versions as $version) {
      $variant_path = $libraryPath . '/versions/' . $version;
      if (is_dir($variant_path) && substr($version, 0, 1) == 'v') {
        $jsdir = '/build';
        $cssdir = '/css';
        // Might be a reduced fingerprint distribution.
        if (!is_dir($variant_path . '/build')) {
          $jsdir = '';
          $cssdir = '';
        }

        $libraries['openlayers-local-' . substr($version, 1)] = [
          'version' => $version,
            'js' => array(
              $base_url . '/libraries/openlayers/versions/' . $version . $jsdir . '/ol.js' => array(
                  'type' => 'external',
              ),
            ),
            'css' => array(
              'component' => array(
                $base_url . '/libraries/openlayers/versions/' . $version . $cssdir . '/ol.css' => array(
                  'type' => 'external',
                ),
              ),
            ),
        ];
      }
    }
  }

  //  TODO - Can we build dynamic library definitions for our js plugins ?

  return $libraries;
}

function openlayers_library_info_alter(&$libraries, $extension) {

  if ($extension == 'openlayers') {

  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc