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_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.
$entity_type: The type of the entity the field is attached to, e.g. 'node' or 'user'.
$field: A field structure.
An array of valid language codes.
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_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_NOT_SPECIFIED,
);
}
}
return $field_langcodes[$entity_type][$field_name];
}