You are here

function ip_language_negotiation_requirements in IP Language Negotiation 7

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

Implements hook_requirements().

File

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

Code

function ip_language_negotiation_requirements($phase) {
  $requirements = array();

  // Ensure translations don't break during installation.
  $t = get_t();
  if ($phase == 'runtime') {
    $requirements['ip_language_negotiation'] = array(
      'title' => $t('IP Language Negotiation'),
      'value' => $t('Properly configured'),
    );
    $enabled_providers = variable_get('language_negotiation_language', array());
    $countries = variable_get('ip_language_negotiation_countries', array());
    $pos_of_url_method = array_search('locale-url', array_keys($enabled_providers));
    $pos_of_ip_method = array_search('ip_language_negotiation', array_keys($enabled_providers));
    if (!isset($enabled_providers['locale-url'])) {
      $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.', array(
        '@link' => url('admin/config/regional/language/configure'),
      ));
      $requirements['ip_language_negotiation']['severity'] = REQUIREMENT_ERROR;
    }
    elseif ($pos_of_url_method >= $pos_of_ip_method) {
      $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.', array(
        '@link' => url('admin/config/regional/language/configure'),
      ));
      $requirements['ip_language_negotiation']['severity'] = REQUIREMENT_ERROR;
    }
    elseif (empty($countries)) {
      $requirements['ip_language_negotiation']['value'] = $t('You need to <a href="@link">set default the language per country</a> for the IP Language Negotiation method to work.', array(
        '@link' => url('admin/config/regional/language/configure/ip'),
      ));
      $requirements['ip_language_negotiation']['severity'] = REQUIREMENT_WARNING;
    }
  }
  return $requirements;
}