You are here

function ip_language_negotiation_requirements in IP Language Negotiation 8

Same name and namespace in other branches
  1. 7 ip_language_negotiation.install \ip_language_negotiation_requirements()

Implements hook_requirements().

File

./ip_language_negotiation.install, line 13
Install/uninstall and update functions.

Code

function ip_language_negotiation_requirements($phase) {
  $requirements = [];
  if ($phase == 'runtime') {
    $requirements['ip_language_negotiation'] = [
      'title' => t('IP Language Negotiation'),
      'value' => t('Properly configured'),
    ];
    $interface_methods = \Drupal::config('language.types')
      ->get('negotiation.language_interface.enabled') ?: [];
    $countries = \Drupal::config('ip_language_negotiation.settings')
      ->get('ip_language_negotiation_countries') ?: [];
    if (!isset($interface_methods['language-url'])) {
      $link = Url::fromRoute('language.negotiation')
        ->toString();
      $requirements['ip_language_negotiation']['value'] = t('You need to <a href="@link">enable the URL language detection method</a> for the IP Language Negotiation method to work.', [
        '@link' => $link,
      ]);
      $requirements['ip_language_negotiation']['severity'] = REQUIREMENT_ERROR;
    }
    else {
      if ($interface_methods['language-url'] >= $interface_methods['ip-language-negotiation-ip']) {
        $link = Url::fromRoute('language.negotiation')
          ->toString();
        $requirements['ip_language_negotiation']['value'] = t('You need to <a href="@link">position the URL language detection method</a> before the IP Language Negotiation method to work.', [
          '@link' => $link,
        ]);
        $requirements['ip_language_negotiation']['severity'] = REQUIREMENT_ERROR;
      }
      else {
        if (empty(array_filter($countries))) {
          $link = Url::fromRoute('ip_language_negotiation.form')
            ->toString();
          $requirements['ip_language_negotiation']['value'] = t('You need to <a href="@link">set a default  language per country</a> for the IP Language Negotiation method to work.', [
            '@link' => $link,
          ]);
          $requirements['ip_language_negotiation']['severity'] = REQUIREMENT_WARNING;
        }
      }
    }
  }
  return $requirements;
}