You are here

function language_hierarchy_language_fallback_candidates_alter in Language Hierarchy 7

Same name and namespace in other branches
  1. 8 language_hierarchy.module \language_hierarchy_language_fallback_candidates_alter()
  2. 2.x language_hierarchy.module \language_hierarchy_language_fallback_candidates_alter()

Implements hook_language_fallback_candidates_alter().

Alter the language fallbacks so that languages only fallback to their ancestors in the hierarchy tree. Root items do not fall back to other root items, or English. This allows constructions of languages where Spanish languages can fallback to a common Spanish ancestor content while bypassing English content.

File

./language_hierarchy.module, line 483

Code

function language_hierarchy_language_fallback_candidates_alter(array &$fallback_candidates) {

  // Get the ancestors of the currently request language. Use these as the fallback language candidates
  $fallback_languages = array_keys(language_hierarchy_get_ancestors($GLOBALS['language']->language, TRUE));

  // If user has special permissions he can always see default language as an ancestor
  $default_language = language_default();
  if (!in_array($default_language->language, $fallback_languages) && user_access('always fallback to default')) {
    $fallback_languages[] = $default_language->language;
  }

  // Language neutral should always be the last item in the list.
  $fallback_languages[] = LANGUAGE_NONE;

  // Overwrite the list of fallback languages with our own ordered, filtered set.
  $fallback_candidates = $fallback_languages;
}