You are here

geolocation_yandex.install in Geolocation Field 8.2

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

Handle requirements.

File

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

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

/**
 * {@inheritdoc}
 *
 * Implements hook_requirements().
 */
function geolocation_yandex_requirements($phase) {
  $requirements = [];
  if ($phase == 'runtime') {
    $requirements['geolocation_yandex_api_key'] = [
      'title' => t('Geolocation - Yandex Maps Key'),
      'value' => t('Yandex Maps key set'),
      'description' => t('A Yandex Maps key is set in the <a href=":geolocation_yandex_settings_url">Geolocation settings</a>.', [
        ':geolocation_yandex_settings_url' => Url::fromRoute('geolocation_yandex.settings')
          ->toString(),
      ]),
      'severity' => REQUIREMENT_OK,
    ];
    if (empty(\Drupal::config('yandex_maps.settings')
      ->get('key'))) {
      $requirements['geolocation_yandex_api_key']['value'] = t('Yandex maps key missing');
      $requirements['geolocation_yandex_api_key']['description'] = t('A Yandex maps key is missing in the <a href=":geolocation_yandex_settings_url">Geolocation settings</a>.', [
        ':geolocation_yandex_settings_url' => Url::fromRoute('geolocation_yandex.settings')
          ->toString(),
      ]);
      $requirements['geolocation_yandex_api_key']['severity'] = REQUIREMENT_WARNING;
    }
  }
  return $requirements;
}

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