geocoder-8.x-3.x-dev/geocoder.module

geocoder.module
<?php

/**
 * @file
 * Geocoder Module.
 */

declare(strict_types=1);

use Drupal\Core\Routing\RouteMatchInterface;

// Ludwig module integration.
if (\Drupal::hasService('ludwig.require_once')) {
  $ludwig_require_once = \Drupal::service('ludwig.require_once');
  $ludwig_require_once->requireOnce('clue/stream-filter', 'src/functions_include.php', dirname(__FILE__));
  $ludwig_require_once->requireOnce('php-http/message', 'src/filters.php', dirname(__FILE__));
}

/**
 * Implements hook_theme().
 */
function geocoder_theme($existing, $type, $theme, $path) {
  return [
    'geocoder_help' => [
      'template' => 'help',
    ],
  ];
}

/**
 * Implements hook_help().
 */
function geocoder_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    // Main module help for the geocoder module.
    case 'help.page.geocoder':
      $element = [
        '#theme' => 'geocoder_help',
      ];

      return \Drupal::service('renderer')->render($element);

    default:
      return '';
  }
}

/**
 * Implements hook_geocoder_provider_info_alter().
 */
function geocoder_geocoder_provider_info_alter(array &$plugins): void {
  // If composer is caching plugin locations remove them.
  // @see https://www.drupal.org/project/drupal/issues/3230708
  $class_loader = \Drupal::service('class_loader');
  if (method_exists($class_loader, 'setApcuPrefix') &&
    ($apcu_prefix = $class_loader->getApcuPrefix() !== NULL)
  ) {
    $apcu_cache_keys = [];
    foreach ($plugins as $plugin) {
      if (!empty($plugin['handler'])) {
        $apcu_cache_keys[] = $apcu_prefix . $plugin['handler'];
      }
    }
    apcu_delete($apcu_cache_keys);
  }

  // Remove plugins for which the providers are not installed.
  $plugins = array_filter($plugins, function (array $plugin): bool {
    return empty($plugin['handler']) || class_exists($plugin['handler']);
  });
}

/**
 * Implements hook_geocode_country_code_alter().
 *
 * Geopunt only works for Belgium, but doesn't include the country in the API
 * response, which may result in unexpected behaviour e.g. Reverse geocoding
 * and saving the result in an address field, since a country is required for
 * address field to work.
 */
function geocoder_geocode_country_code_alter(string &$country_code, array $geojson_array): void {
  if (isset($geojson_array['properties']['providedBy']) && $geojson_array['properties']['providedBy'] === 'geopunt') {
    $country_code = 'BE';
  }
}

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

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