function field_available_languages

7.x 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.


$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

14 calls to field_available_languages()
FieldTranslationsTestCase::testFieldAvailableLanguages in drupal/modules/field/tests/field.test
Ensures that only valid values are returned by field_available_languages().
FieldTranslationsTestCase::testFieldFormTranslationRevisions in drupal/modules/field/tests/field.test
Tests field translations when creating a new revision.
FieldTranslationsTestCase::testFieldInvoke in drupal/modules/field/tests/field.test
Test the multilanguage logic of _field_invoke().
FieldTranslationsTestCase::testFieldInvokeMultiple in drupal/modules/field/tests/field.test
Test the multilanguage logic of _field_invoke_multiple().
FieldTranslationsTestCase::testTranslatableFieldSaveLoad in drupal/modules/field/tests/field.test
Test translatable fields storage/retrieval.

... See full list

1 string reference to 'field_available_languages'
field_info_cache_clear in drupal/modules/field/
Clears the field info cache without clearing the field data cache.


drupal/modules/field/, line 89
Functions implementing Field API multilingual support.


function field_available_languages($entity_type, $field) {
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['field_languages'] = &drupal_static(__FUNCTION__);
  $field_languages = &$drupal_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,
      drupal_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];