function domain_variable_locale_init in Domain Variable 7
Implements hook_init().
Overrides static_cache for language_list function.
File
- domain_variable_locale/
domain_variable_locale.module, line 13 - Set enabled Languages per Domain realm.
Code
function domain_variable_locale_init() {
// Get the language_list variable and continue if the variable has been set.
$language_list = variable_get('language_list');
if (!$language_list) {
return;
}
// Do not continue if this is Drupal's default admin page for languages.
if (current_path() == 'admin/config/regional/language') {
return;
}
// Initialize the language list() function from Drupal Core's bootstrap.inc.
// It will be cached by drupal_static(). We clone its results, alter it and
// then overwrite the drupal_static() result.
$existing_languages = language_list();
// When a new language is added, the key it's not available in language_list
// until the domain form is saved; so we mark it as disabled here.
$new_languages = array_diff_key($existing_languages, $language_list);
if (!empty($new_languages)) {
$new_language_list = array_fill_keys(array_keys($new_languages), 0);
$language_list += $new_language_list;
}
// Clone drupal_static result and reset its cache.
$language_list_static_clone = drupal_static("language_list");
drupal_static_reset('language_list');
// Iterate over variable 'language_list' and unset all languages that are
// disabled for this Realm.
foreach ($language_list as $language_key => $enabled) {
if (!$enabled) {
_domain_variable_locale_recursive_unset($language_list_static_clone, $language_key);
}
}
// Assign changed results to drupal_static() again.
$languages =& drupal_static('language_list');
$languages = $language_list_static_clone;
}