1 field.multilingual.inc field_available_languages($entity_type, $field)

Collects the available languages for the given entity type and field.

If the given field has language support enabled, an array of available languages will be returned, otherwise only LANGUAGE_NONE will be returned. Since the default value for a 'translatable' entity property is FALSE, we ensure that only entities that are able to handle translations actually get translatable fields.

Parameters

$entity_type: The type of the entity the field is attached to, e.g. 'node' or 'user'.

$field: A field structure.

Return value

An array of valid language codes.

Related topics

File

core/modules/field/field.multilingual.inc, line 102
Functions implementing Field API multilingual support.

Code

function field_available_languages($entity_type, $field) {
  static $backdrop_static_fast;
  if (!isset($backdrop_static_fast)) {
    $backdrop_static_fast['field_languages'] = &backdrop_static(__FUNCTION__);
  }
  $field_languages = &$backdrop_static_fast['field_languages'];
  $field_name = $field['field_name'];

  if (!isset($field_languages[$entity_type][$field_name])) {
    // If the field has language support enabled we retrieve an (alterable) list
    // of enabled languages, otherwise we return just LANGUAGE_NONE.
    if (field_is_translatable($entity_type, $field)) {
      $languages = field_content_languages();
      // Let other modules alter the available languages.
      $context = array('entity_type' => $entity_type, 'field' => $field);
      backdrop_alter('field_available_languages', $languages, $context);
      $field_languages[$entity_type][$field_name] = $languages;
    }
    else {
      $field_languages[$entity_type][$field_name] = array(LANGUAGE_NONE);
    }
  }

  return $field_languages[$entity_type][$field_name];
}