You are here

function geolocation_google_maps_requirements in Geolocation Field 8.3

Same name and namespace in other branches
  1. 8.2 modules/geolocation_google_maps/geolocation_google_maps.install \geolocation_google_maps_requirements()

Implements hook_requirements().

File

modules/geolocation_google_maps/geolocation_google_maps.install, line 15
Handle requirements.

Code

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;
}