function field_available_languages

Collects the available language codes for the given entity type and field.

If the given field has language support enabled, an array of available language codes will be returned, otherwise only Language::LANGCODE_NOT_SPECIFIED 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

14 calls to field_available_languages()
field_invoke_method in drupal/core/modules/field/field.attach.inc
Invokes a method on all the fields of a given entity.
field_invoke_method_multiple in drupal/core/modules/field/field.attach.inc
Invokes a method across fields on multiple entities.
field_sql_storage_field_storage_write in drupal/core/modules/field_sql_storage/field_sql_storage.module
Implements hook_field_storage_write().
field_test_field_storage_load in drupal/core/modules/field/tests/modules/field_test/field_test.storage.inc
Implements hook_field_storage_load().
field_test_field_storage_write in drupal/core/modules/field/tests/modules/field_test/field_test.storage.inc
Implements hook_field_storage_write().

... See full list

2 string references to 'field_available_languages'
EntityQueryTest::setUp in drupal/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php
Sets up Drupal unit test environment.
field_info_cache_clear in drupal/core/modules/field/field.info.inc
Clears the field info cache without clearing the field data cache.

File

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

Code

function field_available_languages($entity_type, $field) {
  static $drupal_static_fast;
  if (!isset($drupal_static_fast)) {
    $drupal_static_fast['field_langcodes'] =& drupal_static(__FUNCTION__);
  }
  $field_langcodes =& $drupal_static_fast['field_langcodes'];
  $field_name = $field['field_name'];
  if (!isset($field_langcodes[$entity_type][$field_name])) {

    // If the field has language support enabled we retrieve an (alterable) list
    // of enabled languages, otherwise we return just Language::LANGCODE_NOT_SPECIFIED.
    if (field_is_translatable($entity_type, $field)) {
      $langcodes = field_content_languages();

      // Let other modules alter the available languages.
      $context = array(
        'entity_type' => $entity_type,
        'field' => $field,
      );
      drupal_alter('field_available_languages', $langcodes, $context);
      $field_langcodes[$entity_type][$field_name] = $langcodes;
    }
    else {
      $field_langcodes[$entity_type][$field_name] = array(
        Language::LANGCODE_NOT_SPECIFIED,
      );
    }
  }
  return $field_langcodes[$entity_type][$field_name];
}