You are here

function domain_locale_install in Domain Locale 7

Same name and namespace in other branches
  1. 6 domain_locale.install \domain_locale_install()

Implements hook_install().

File

./domain_locale.install, line 10
Provides domain specific locale settings

Code

function domain_locale_install() {

  // Make all enabled languages available on all domains by default
  $enabled_languages = db_query('SELECT language, weight FROM {languages} WHERE enabled=1');
  module_load_include('module', 'domain');
  $existing_domains = domain_domains();
  foreach ($enabled_languages as $lang) {
    $current_language = $lang->language;
    $language_weight = $lang->weight;
    foreach ($existing_domains as $current_domain) {
      if ($current_domain['domain_id'] > 0) {
        db_insert('domain_locale')
          ->fields(array(
          'language' => $current_language,
          'domain_id' => $current_domain['domain_id'],
          'weight' => $language_weight,
        ))
          ->execute();
      }
    }
  }

  // Make all languages enabled under the hood
  db_update('languages')
    ->fields(array(
    'enabled' => 1,
  ))
    ->execute();

  // Set domain_locale higher than i18n if it exists
  $result = db_query("SELECT weight FROM {system} WHERE name = 'i18n'")
    ->fetch();
  if ($result) {
    $weight = $result->weight + 1;
    $ret[] = db_update('system')
      ->fields(array(
      'weight' => $weight,
    ))
      ->condition('name', 'domain_locale')
      ->execute();
  }
}