geolocation-8.x-3.x-dev/modules/geolocation_google_maps/geolocation_google_maps.install
modules/geolocation_google_maps/geolocation_google_maps.install
<?php
/**
* @file
* Handle requirements.
*/
use Drupal\Core\Url;
/**
* Implements hook_requirements().
*/
function geolocation_google_maps_requirements(string $phase): array {
$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(): void {
Drupal::configFactory()->getEditable('geolocation_google_maps.settings')->delete();
}
