function locale_field_language_fallback in Drupal 7
Applies language fallback rules to the fields attached to the given entity.
Core language fallback rules simply check if fields have a field translation for the requested language code. If so the requested language is returned, otherwise all the fallback candidates are inspected to see if there is a field translation available in another language. By default this is called by locale_field_language_alter(), but this behavior can be disabled by setting the 'locale_field_language_fallback' variable to FALSE.
Parameters
$display_language: A reference to an array of language codes keyed by field name.
$entity: The entity to be displayed.
$langcode: The language code $entity has to be displayed in.
3 calls to locale_field_language_fallback()
- field_test_field_language_alter in modules/
field/ tests/ field_test.module - Implements hook_field_language_alter().
- hook_field_language_alter in modules/
field/ field.api.php - Perform alterations on field_language() values.
- locale_field_language_alter in modules/
locale/ locale.module - Implements hook_field_language_alter().
3 string references to 'locale_field_language_fallback'
- hook_field_language_alter in modules/
field/ field.api.php - Perform alterations on field_language() values.
- locale_field_language_alter in modules/
locale/ locale.module - Implements hook_field_language_alter().
- locale_uninstall in modules/
locale/ locale.install - Implements hook_uninstall().
File
- modules/
locale/ locale.module, line 496 - Add language handling functionality and enables the translation of the user interface to languages other than English.
Code
function locale_field_language_fallback(&$display_language, $entity, $langcode) {
// Lazily init fallback candidates to avoid unnecessary calls.
$fallback_candidates = NULL;
$field_languages = array();
foreach ($display_language as $field_name => $field_language) {
// If the requested language is defined for the current field use it,
// otherwise search for a fallback value among the fallback candidates.
if (isset($entity->{$field_name}[$langcode])) {
$display_language[$field_name] = $langcode;
}
elseif (!empty($entity->{$field_name})) {
if (!isset($fallback_candidates)) {
require_once DRUPAL_ROOT . '/includes/language.inc';
$fallback_candidates = language_fallback_get_candidates();
}
foreach ($fallback_candidates as $fallback_language) {
if (isset($entity->{$field_name}[$fallback_language])) {
$display_language[$field_name] = $fallback_language;
break;
}
}
}
}
}