You are here

geolocation.install in Geolocation Field 8

Handle requirements.

File

geolocation.install
View source
<?php

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

/**
 * Implements hook_requirements().
 */
function geolocation_requirements($phase) {
  $requirements = [];
  if ($phase == 'runtime') {
    $requirements['geolocation_api_key'] = [
      'title' => t('Geolocation - Google Maps API Key'),
      'value' => t('A Google Maps API key is set in the <a href=":geolocation_settings_url">Geolocation settings</a>, required to display any Google maps.', [
        ':geolocation_settings_url' => Url::fromRoute('geolocation.settings')
          ->toString(),
      ]),
      'severity' => REQUIREMENT_OK,
    ];
    if (empty(\Drupal::config('geolocation.settings')
      ->get('google_map_api_key'))) {
      $requirements['geolocation_api_key']['value'] = t('A Google Maps API key required to display any Google maps is missing in the <a href=":geolocation_settings_url">Geolocation settings</a>.', [
        ':geolocation_settings_url' => Url::fromRoute('geolocation.settings')
          ->toString(),
      ]);
      $requirements['geolocation_api_key']['severity'] = REQUIREMENT_WARNING;
    }
  }
  return $requirements;
}

Functions

Namesort descending Description
geolocation_requirements Implements hook_requirements().