1, 'path' => drupal_get_path('module', 'openlayers') . '/includes', ); } /** * Implements hook_permission(). */ function openlayers_permission() { return array( 'administer openlayers' => array( 'title' => t('Administer Openlayers'), 'description' => t('Configure Openlayers settings, styles, maps, and layers.'), ), ); } /** * Implements hook_element_info(). */ function openlayers_element_info() { return array( 'openlayers' => array( '#input' => FALSE, '#tree' => TRUE, '#process' => array('openlayers_element_process_callback'), '#pre_render' => array('openlayers_element_prerender_callback'), '#theme_wrappers' => array('form_element'), ), ); } /** * Process callback for the openlayers form element. * * Renders the map and returns the markup in an renderable array. */ function openlayers_element_process_callback($element, $form_state, $complete_form) { /** @var \Drupal\openlayers\Types\MapInterface $map */ if (($map = Openlayers::load('Map', $element['#map'])) == TRUE) { $element['map'] = $map->build(); } return $element; } /** * Pre render callback for the openlayers form element. */ function openlayers_element_prerender_callback($element) { if (empty($element['map'])) { /** @var \Drupal\openlayers\Types\Map $map */ if (($map = Openlayers::load('Map', $element['#map'])) == TRUE) { $element['map'] = $map->build(); } } return $element; } /** * Implements hook_theme(). */ function openlayers_theme($existing, $type, $theme, $path) { return array( 'openlayers' => array( 'path' => $path . '/theme', 'template' => 'openlayers', 'render element' => 'openlayers', 'file' => 'openlayers.theme.inc', ), ); } /** * Implements hook_i18n_string_info(). */ function openlayers_i18n_string_info() { $groups['openlayers'] = array( 'title' => t('Openlayers'), 'format' => TRUE, ); return $groups; } /** * Translate a string using i18n_string, if available. * * @param string $name * Textgroup and context glued with ':'. * @param string $default * String in default language. Default language may or may not be English. * @param array $options * An associative array of additional options, with the following keys: * - langcode: the language code to translate to a language other than what is * used to display the page; defaults to the current language * - filter: filtering callback to apply to the translated string only * - format: input format to apply to the translated string only * - callback: callback to apply to the result (both to the translated or * untranslated string) * - update: whether to update source table; defaults to FALSE * - translate: whether to return a translation; defaults to TRUE. * * @return string * The translated string if i18n_string is available, the original otherwise. * * @see i18n_string() */ function openlayers_i18n_string($name, $default, array $options = array()) { if (module_exists('i18n_string')) { $result = i18n_string($name, $default, $options); } else { $result = $default; $options += array( 'format' => NULL, 'sanitize' => FALSE, ); if ($options['sanitize']) { $result = check_markup($result, $options['format']); } } return $result; } /** * Wrapper to update / create translation source for user defined strings. * * Wrapper around i18n_string_update() that ensures the module is available. * * @param string|array $name * Array or string concatenated with ':' that contains textgroup and string * context. * @param string $string * Source string in default language. Default language may or may not be * English. Array of key => string to update multiple strings at once. * @param array $options * Array with additional options: * - 'format', String format if the string has text format * - 'messages', Whether to print out status messages. * * @return mixed * Same return as from i18n_string_update() * * @see i18n_string_update() */ function openlayers_i18n_string_update($name, $string, array $options = array()) { if (module_exists('i18n_string')) { return i18n_string_update($name, $string, $options); } } /** * Wrapper to remove source and translations for user defined string. * * Though for most strings the 'name' or 'string id' uniquely identifies that * string, there are some exceptions (like profile categories) for which we need * to use the source string itself as a search key. * * @param string $name * String name. * @param string $string * Optional source string (string in default language). * @param array $options * Array of string properties to remove. * * @return mixed * Same return as from i18n_string_remove() * * @see i18n_string_remove() */ function openlayers_i18n_string_remove($name, $string = NULL, array $options = array()) { if (module_exists('i18n_string')) { return i18n_string_remove($name, $string, $options); } } /** * Implements hook_i18n_string_refresh(). */ function openlayers_i18n_string_refresh() { foreach (Openlayers::getPluginTypes() as $type) { foreach (Openlayers::loadAllExportable($type) as $exportable) { $object = Openlayers::load($type, $exportable); $object->i18nStringsRefresh(); } } } /** * Implements hook_libraries_info(). */ function openlayers_libraries_info() { // During an upgrade from Openlayers 7.x-2.x branch, the new registry_autoload // dependency may not be enabled, which makes it impossible to use the new // namespaced classes. So provide a fallback variable instead. $js_css_group = 'openlayers'; if (class_exists('Drupal\openlayers\Config') && class_exists('OpenlayersDrupal')) { $js_css_group = Config::get('openlayers.js_css.group'); } $module_path = drupal_get_path('module', 'openlayers'); $library_path = libraries_get_path('openlayers3'); if (is_dir($library_path) && is_dir($library_path . '/versions')) { $versions = scandir($library_path . '/versions'); } else { $versions = []; } $local_variants = []; foreach ($versions as $version) { $variant_path = $library_path . '/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 = ''; } $local_variants['local:' . substr($version, 1)] = [ 'name' => 'Openlayers ' . $version, 'files' => array( 'js' => array( 'versions/' . $version . $jsdir . '/ol.js' => array( 'type' => 'file', 'weight' => 6, 'group' => $js_css_group, ), ), 'css' => array( 'versions/' . $version . $cssdir . '/ol.css' => array( 'type' => 'file', 'weight' => 4, 'group' => $js_css_group, ), ), ), ]; } } ksort($local_variants); $cdn_variants = array( 'cdn:7.3.0' => array( 'name' => 'Openlayers v7.3.0 (CDN)', 'files' => array( 'js' => array( 'https://cdn.jsdelivr.net/npm/ol@v7.3.0/dist/ol.js' => array( 'type' => 'external', 'data' => 'https://cdn.jsdelivr.net/npm/ol@v7.3.0/dist/ol.js', ), ), 'css' => array( 'https://cdn.jsdelivr.net/npm/ol@v7.3.0/ol.css' => array( 'type' => 'external', 'data' => 'https://cdn.jsdelivr.net/npm/ol@v7.3.0/ol.css', ), ), ), ), 'cdn:7.5.2' => array( 'name' => 'Openlayers v7.5.2 (CDN)', 'files' => array( 'js' => array( 'https://cdn.jsdelivr.net/npm/ol@v7.5.2/dist/ol.js' => array( 'type' => 'external', 'data' => 'https://cdn.jsdelivr.net/npm/ol@v7.5.2/dist/ol.js', ), ), 'css' => array( 'https://cdn.jsdelivr.net/npm/ol@v7.5.2/ol.css' => array( 'type' => 'external', 'data' => 'https://cdn.jsdelivr.net/npm/ol@v7.5.2/ol.css', ), ), ), ), 'cdn:8.1.0' => array( 'name' => 'Openlayers v8.1.0 (CDN)', 'files' => array( 'js' => array( 'https://cdn.jsdelivr.net/npm/ol@v8.1.0/dist/ol.js' => array( 'type' => 'external', 'data' => 'https://cdn.jsdelivr.net/npm/ol@v8.1.0/dist/ol.js', ), ), 'css' => array( 'https://cdn.jsdelivr.net/npm/ol@v8.1.0/ol.css' => array( 'type' => 'external', 'data' => 'https://cdn.jsdelivr.net/npm/ol@v8.1.0/ol.css', ), ), ), ), 'cdn:8.2.0' => array( 'name' => 'Openlayers v8.2.0 (CDN)', 'files' => array( 'js' => array( 'https://cdn.jsdelivr.net/npm/ol@v8.2.0/dist/ol.js' => array( 'type' => 'external', 'data' => 'https://cdn.jsdelivr.net/npm/ol@v8.2.0/dist/ol.js', ), ), 'css' => array( 'https://cdn.jsdelivr.net/npm/ol@v8.2.0/ol.css' => array( 'type' => 'external', 'data' => 'https://cdn.jsdelivr.net/npm/ol@v8.2.0/ol.css', ), ), ), ), 'cdn:9.0.0' => array( 'name' => 'Openlayers v9.0.0 (CDN)', 'files' => array( 'js' => array( 'https://cdn.jsdelivr.net/npm/ol@v9.0.0/dist/ol.js' => array( 'type' => 'external', 'data' => 'https://cdn.jsdelivr.net/npm/ol@v9.0.0/dist/ol.js', ), ), 'css' => array( 'https://cdn.jsdelivr.net/npm/ol@v9.0.0/ol.css' => array( 'type' => 'external', 'data' => 'https://cdn.jsdelivr.net/npm/ol@v9.0.0/ol.css', ), ), ), ), ); $version = Openlayers::getLibraryVersion(); $libraries['openlayers3_integration'] = array( 'name' => 'Openlayers 3 Drupal integration files', 'vendor url' => 'https://drupal.org/project/openlayers', 'download url' => 'https://drupal.org/project/openlayers', 'version' => $version, 'library path' => $module_path, 'files' => array( 'js' => array( $module_path . '/js/openlayers.js' => array( 'data' => $module_path . '/js/openlayers.js', 'type' => 'file', 'weight' => 8, 'group' => $js_css_group, ), $module_path . '/js/openlayers.pluginManager.js' => array( 'data' => $module_path . '/js/openlayers.pluginManager.js', 'type' => 'file', 'weight' => 12, 'group' => $js_css_group, ), $module_path . '/js/openlayers.behaviors.js' => array( 'data' => $module_path . '/js/openlayers.behaviors.js', 'type' => 'file', 'weight' => 14, 'group' => $js_css_group, ), ), 'css' => array( $module_path . '/css/openlayers.css' => array( 'data' => $module_path . '/css/openlayers.css', 'type' => 'file', 'weight' => 4, 'group' => $js_css_group, ), ), ), 'variants' => array( 'debug' => array( 'files' => array( 'js' => array( 'js/openlayers.js' => array( 'type' => 'file', 'weight' => 8, 'group' => $js_css_group, ), 'js/openlayers.pluginManager.js' => array( 'type' => 'file', 'weight' => 12, 'group' => $js_css_group, ), 'js/openlayers.behaviors.js' => array( 'type' => 'file', 'weight' => 14, 'group' => $js_css_group, ), 'js/openlayers.console.js' => array( 'type' => 'file', 'weight' => 16, 'group' => $js_css_group, ), 'js/openlayers.debug.js' => array( 'type' => 'file', 'weight' => 18, 'group' => $js_css_group, ), ), 'css' => array( 'css/openlayers.css' => array( 'type' => 'file', 'weight' => 4, 'group' => $js_css_group, ), ), ), ), ), ); $variants = array_merge($local_variants, $cdn_variants); $libraries['openlayers3'] = array( 'name' => 'Openlayers 3', 'vendor url' => 'http://openlayers.org/', 'download url' => 'https://github.com/openlayers/ol3/releases/download/v3.11.2/v3.11.2.zip', 'version callback' => array( '\Drupal\openlayers\Openlayers', 'getLibraryVersion', ), 'version arguments' => array(), 'library path' => $module_path, // This is taken in account if the module libraries_cdn is enabled. 'cdn' => array( 'aliases' => array('ol3'), 'options' => array( 'weight' => 0, 'group' => $js_css_group, ), 'request' => array( // Maximum 10 seconds for the http requests to CDNs. 'timeout' => 10, ), ), 'variants' => $variants, 'dependencies' => array( 'openlayers3_integration', ), ); unset($libraries['openlayers3']['library path']); $libraries['openlayers3']['variants'] = $variants; return $libraries; } /** * Implements hook_hook_info(). */ function openlayers_hook_info() { $hooks = array( 'openlayers_object_preprocess_alter', 'openlayers_object_postprocess_alter', ); return array_fill_keys($hooks, array('group' => 'openlayers')); } /** * Implements hook_stream_wrappers_alter(). */ function openlayers_stream_wrappers_alter(&$wrappers) { if (!class_exists('OpenlayersDrupal')) { // During an upgrade from Openlayers 7.x-3.1 to 7.x-3.2 version, ensure the // new namespaced classes for the service container are available. If not, // run a registry update using the registry_autoload dependency. require_once DRUPAL_ROOT . '/includes/registry.inc'; _registry_update(); } if (class_exists('OpenlayersServiceContainer')) { OpenlayersServiceContainer::init(); } } /** * Implements hook_modules_enabled(). */ function openlayers_modules_enabled() { if (class_exists('OlServiceContainer')) { ServiceContainer::reset(); ServiceContainer::init(); } } /** * Implements hook_module_implements_alter(). */ function openlayers_module_implements_alter(&$implementations, $hook) { // Moves our hook_init() implementation to occur first so that we // can initialize the container. if ($hook == 'stream_wrappers_alter') { $group = $implementations['openlayers']; unset($implementations['openlayers']); $implementations = array('openlayers' => $group) + $implementations; } } /** * Implements hook_ctools_plugin_type(). */ function openlayers_ctools_plugin_type() { $items['ServiceProvider'] = array( 'cache' => FALSE, ); return $items; } /** * Implements hook_ctools_plugin_directory(). */ function openlayers_ctools_plugin_directory($owner, $plugin_type) { if ($owner == 'openlayers') { return 'src/ServiceContainer/' . $plugin_type; } return NULL; }