You are here

geolocation_google_maps.install in Geolocation Field 8.2

Same filename and directory in other branches
  1. 8.3 modules/geolocation_google_maps/geolocation_google_maps.install

Handle requirements.

File

modules/geolocation_google_maps/geolocation_google_maps.install
View source
<?php

/**
 * @file
 * Handle requirements.
 */
use Drupal\Core\Url;

/**
 * {@inheritdoc}
 *
 * Implements hook_requirements().
 */
function geolocation_google_maps_requirements($phase) {
  $requirements = [];
  if ($phase == 'runtime') {
    $requirements['geolocation_google_maps_api_key'] = [
      'title' => t('Geolocation - Google Maps API Key'),
      'value' => t('Google Maps API key set'),
      'description' => t('A Google Maps API key or client ID is set in the <a href=":geolocation_google_maps_settings_url">Geolocation settings</a>, required to display any Google maps.', [
        ':geolocation_google_maps_settings_url' => Url::fromRoute('geolocation_google_maps.settings')
          ->toString(),
      ]),
      'severity' => REQUIREMENT_OK,
    ];
    if (empty(\Drupal::config('geolocation_google_maps.settings')
      ->get('google_map_api_key')) && empty(\Drupal::config('geolocation_google_maps.settings')
      ->get('google_map_custom_url_parameters')['client'])) {
      $requirements['geolocation_google_maps_api_key']['value'] = t('Google Maps API key or client ID missing');
      $requirements['geolocation_google_maps_api_key']['description'] = t('A Google Maps API key or client ID required to display any Google maps is missing in the <a href=":geolocation_google_maps_settings_url">Geolocation settings</a>.', [
        ':geolocation_google_maps_settings_url' => Url::fromRoute('geolocation_google_maps.settings')
          ->toString(),
      ]);
      $requirements['geolocation_google_maps_api_key']['severity'] = REQUIREMENT_WARNING;
    }
    elseif (\Drupal::config('geolocation_google_maps.settings')
      ->get('google_map_api_key') === 'AIzaSyChy7jQvcJpTpIiupQhq4wacdVzdum3hvc') {
      $requirements['geolocation_google_maps_api_key']['value'] = t('Google Maps API Demo key use');
      $requirements['geolocation_google_maps_api_key']['description'] = t('Do not use the Geolocation Google Maps API Demo key in the <a href=":geolocation_google_maps_settings_url">Geolocation settings</a>.', [
        ':geolocation_google_maps_settings_url' => Url::fromRoute('geolocation_google_maps.settings')
          ->toString(),
      ]);
      $requirements['geolocation_google_maps_api_key']['severity'] = REQUIREMENT_ERROR;
    }
  }
  return $requirements;
}

/**
 * Implements hook_requirements().
 */
function geolocation_google_maps_uninstall() {
  Drupal::configFactory()
    ->getEditable('geolocation_google_maps.settings')
    ->delete();
}