function locale_update_8003

Converts language domains to new format.

Related topics

File

drupal/core/modules/locale/locale.install, line 469
Install, update, and uninstall functions for the Locale module.

Code

function locale_update_8003() {
  $message = '';
  $config = config('language.negotiation');
  $domains = $config
    ->get('url.domains') ?: array();

  // $used_domains keeps track of the domain names in use.
  $used_domains = array();
  foreach ($domains as $langcode => $domain) {

    // Domain names can not contain protocol and/or ports.
    if (!empty($domain)) {
      $host = 'http://' . str_replace(array(
        'http://',
        'https://',
      ), '', $domain);
      if (parse_url($host, PHP_URL_HOST) != $domain) {
        $domains[$langcode] = parse_url($host, PHP_URL_HOST);
      }
      if (array_key_exists($domain, $used_domains)) {
        if (empty($message)) {
          $message = 'Some languages are using the same domain name, you should change these domain names at ' . l('URL language detection configuration', 'admin/config/regional/language/configure/url' . '.');
        }
      }
      else {
        $used_domains[$domain] = $domain;
      }
    }
  }
  $config
    ->set('url.domains', $domains)
    ->save();
  if (!empty($message)) {
    return $message;
  }
}