function field_language_fallback

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 field_field_language_alter(), but this behavior can be disabled by setting the 'field_language_fallback' variable to FALSE.

Parameters

$field_langcodes: 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.

Related topics

3 calls to field_language_fallback()
field_language in drupal/core/modules/field/field.multilingual.inc
Returns the display language code for the fields attached to the given entity.
field_test_field_language_alter in drupal/core/modules/field/tests/modules/field_test/field_test.module
Implements hook_field_language_alter().
hook_field_language_alter in drupal/core/modules/field/field.api.php
Perform alterations on field_language() values.
4 string references to 'field_language_fallback'
field_language in drupal/core/modules/field/field.multilingual.inc
Returns the display language code for the fields attached to the given entity.
field_language_delete in drupal/core/modules/field/field.multilingual.inc
Implements hook_language_delete().
field_language_insert in drupal/core/modules/field/field.multilingual.inc
Implements hook_language_insert().
hook_field_language_alter in drupal/core/modules/field/field.api.php
Perform alterations on field_language() values.

File

drupal/core/modules/field/field.module, line 444
Attach custom data fields to Drupal entities.

Code

function field_language_fallback(&$field_langcodes, $entity, $langcode) {

  // Lazily init fallback candidates to avoid unnecessary calls.
  $fallback_candidates = NULL;
  foreach ($field_langcodes as $field_name => $field_langcode) {

    // 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])) {
      $field_langcodes[$field_name] = $langcode;
    }
    elseif (!empty($entity->{$field_name})) {
      if (!isset($fallback_candidates)) {
        require_once DRUPAL_ROOT . '/core/includes/language.inc';
        $fallback_candidates = language_fallback_get_candidates();
      }
      foreach ($fallback_candidates as $fallback_langcode) {
        if (isset($entity->{$field_name}[$fallback_langcode])) {
          $field_langcodes[$field_name] = $fallback_langcode;
          break;
        }
      }
    }
  }
}