You are here

ip_language_negotiation.install in IP Language Negotiation 8

Same filename and directory in other branches
  1. 7 ip_language_negotiation.install

Install/uninstall and update functions.

File

ip_language_negotiation.install
View source
<?php

use Drupal\Core\Url;

/**
 * @file
 * Install/uninstall and update functions.
 */

/**
 * Implements hook_requirements().
 */
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;
}

/**
 * Implements hook_uninstall().
 */
function ip_language_negotiation_uninstall() {
  $config = \Drupal::configFactory()
    ->getEditable('ip_language_negotiation.settings');
  $config
    ->clear('ip_language_negotiation_countries');
  $config
    ->save();
}