Commit 47556803 authored by Dries's avatar Dries
Browse files

- Patch #1439692 by clemens.tolboom, plach, dawehner, das-peter, Gábor Hojtsy:...

- Patch #1439692 by clemens.tolboom, plach, dawehner, das-peter, Gábor Hojtsy: Rename field language properties to langcode.
parent 99d9ca8e
......@@ -265,9 +265,9 @@ public function entityCondition($name, $value, $operator = NULL) {
* @param $delta_group
* An arbitrary identifier: conditions in the same group must have the same
* $delta_group.
* @param $language_group
* @param $langcode_group
* An arbitrary identifier: conditions in the same group must have the same
* $language_group.
* $langcode_group.
*
* @return EntityFieldQuery
* The called object.
......@@ -275,8 +275,8 @@ public function entityCondition($name, $value, $operator = NULL) {
* @see EntityFieldQuery::addFieldCondition
* @see EntityFieldQuery::deleted
*/
public function fieldCondition($field, $column = NULL, $value = NULL, $operator = NULL, $delta_group = NULL, $language_group = NULL) {
return $this->addFieldCondition($this->fieldConditions, $field, $column, $value, $operator, $delta_group, $language_group);
public function fieldCondition($field, $column = NULL, $value = NULL, $operator = NULL, $delta_group = NULL, $langcode_group = NULL) {
return $this->addFieldCondition($this->fieldConditions, $field, $column, $value, $operator, $delta_group, $langcode_group);
}
/**
......@@ -291,9 +291,9 @@ public function fieldCondition($field, $column = NULL, $value = NULL, $operator
* @param $delta_group
* An arbitrary identifier: conditions in the same group must have the same
* $delta_group.
* @param $language_group
* @param $langcode_group
* An arbitrary identifier: conditions in the same group must have the same
* $language_group.
* $langcode_group.
*
* @return EntityFieldQuery
* The called object.
......@@ -301,8 +301,8 @@ public function fieldCondition($field, $column = NULL, $value = NULL, $operator
* @see EntityFieldQuery::addFieldCondition
* @see EntityFieldQuery::deleted
*/
public function fieldLanguageCondition($field, $value = NULL, $operator = NULL, $delta_group = NULL, $language_group = NULL) {
return $this->addFieldCondition($this->fieldMetaConditions, $field, 'language', $value, $operator, $delta_group, $language_group);
public function fieldLanguageCondition($field, $value = NULL, $operator = NULL, $delta_group = NULL, $langcode_group = NULL) {
return $this->addFieldCondition($this->fieldMetaConditions, $field, 'langcode', $value, $operator, $delta_group, $langcode_group);
}
/**
......@@ -317,9 +317,9 @@ public function fieldLanguageCondition($field, $value = NULL, $operator = NULL,
* @param $delta_group
* An arbitrary identifier: conditions in the same group must have the same
* $delta_group.
* @param $language_group
* @param $langcode_group
* An arbitrary identifier: conditions in the same group must have the same
* $language_group.
* $langcode_group.
*
* @return EntityFieldQuery
* The called object.
......@@ -327,8 +327,8 @@ public function fieldLanguageCondition($field, $value = NULL, $operator = NULL,
* @see EntityFieldQuery::addFieldCondition
* @see EntityFieldQuery::deleted
*/
public function fieldDeltaCondition($field, $value = NULL, $operator = NULL, $delta_group = NULL, $language_group = NULL) {
return $this->addFieldCondition($this->fieldMetaConditions, $field, 'delta', $value, $operator, $delta_group, $language_group);
public function fieldDeltaCondition($field, $value = NULL, $operator = NULL, $delta_group = NULL, $langcode_group = NULL) {
return $this->addFieldCondition($this->fieldMetaConditions, $field, 'delta', $value, $operator, $delta_group, $langcode_group);
}
/**
......@@ -367,14 +367,14 @@ public function fieldDeltaCondition($field, $value = NULL, $operator = NULL, $de
* against any combination of deltas. By passing the conditions with the
* same $delta_group it will ensure that only values attached to the same
* delta are matched, and entity 1 would then be excluded from the results.
* @param $language_group
* @param $langcode_group
* An arbitrary identifier: conditions in the same group must have the same
* $language_group.
* $langcode_group.
*
* @return EntityFieldQuery
* The called object.
*/
protected function addFieldCondition(&$conditions, $field, $column = NULL, $value = NULL, $operator = NULL, $delta_group = NULL, $language_group = NULL) {
protected function addFieldCondition(&$conditions, $field, $column = NULL, $value = NULL, $operator = NULL, $delta_group = NULL, $langcode_group = NULL) {
if (is_scalar($field)) {
$field_definition = field_info_field($field);
if (empty($field_definition)) {
......@@ -392,7 +392,7 @@ protected function addFieldCondition(&$conditions, $field, $column = NULL, $valu
'value' => $value,
'operator' => $operator,
'delta_group' => $delta_group,
'language_group' => $language_group,
'langcode_group' => $langcode_group,
);
}
return $this;
......
......@@ -1526,7 +1526,9 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
sort($results);
sort($intended_results);
}
$this->assertEqual($results, $intended_results, $message);
if (!$this->assertEqual($results, $intended_results, $message)) {
debug($results, $message);
}
}
catch (Exception $e) {
$this->fail('Exception thrown: '. $e->getMessage());
......
......@@ -1459,10 +1459,10 @@ function hook_field_attach_prepare_translation_alter(&$entity, $context) {
/**
* Perform alterations on field_language() values.
*
* This hook is invoked to alter the array of display languages for the given
* entity.
* This hook is invoked to alter the array of display language codes for the
* given entity.
*
* @param $display_language
* @param $display_langcode
* A reference to an array of language codes keyed by field name.
* @param $context
* An associative array containing:
......@@ -1470,11 +1470,11 @@ function hook_field_attach_prepare_translation_alter(&$entity, $context) {
* - entity: The entity with fields to render.
* - langcode: The language code $entity has to be displayed in.
*/
function hook_field_language_alter(&$display_language, $context) {
function hook_field_language_alter(&$display_langcode, $context) {
// Do not apply core language fallback rules if they are disabled or if Locale
// is not registered as a translation handler.
if (variable_get('locale_field_language_fallback', TRUE) && field_has_translation_handler($context['entity_type'], 'locale')) {
locale_field_language_fallback($display_language, $context['entity'], $context['language']);
locale_field_language_fallback($display_langcode, $context['entity'], $context['langcode']);
}
}
......@@ -1482,22 +1482,22 @@ function hook_field_language_alter(&$display_language, $context) {
* Alter field_available_languages() values.
*
* This hook is invoked from field_available_languages() to allow modules to
* alter the array of available languages for the given field.
* alter the array of available language codes for the given field.
*
* @param $languages
* @param $langcodes
* A reference to an array of language codes to be made available.
* @param $context
* An associative array containing:
* - entity_type: The type of the entity the field is attached to.
* - field: A field data structure.
*/
function hook_field_available_languages_alter(&$languages, $context) {
// Add an unavailable language.
$languages[] = 'xx';
function hook_field_available_languages_alter(&$langcodes, $context) {
// Add an unavailable language code.
$langcodes[] = 'xx';
// Remove an available language.
$index = array_search('yy', $languages);
unset($languages[$index]);
// Remove an available language code.
$index = array_search('yy', $langcodes);
unset($langcodes[$index]);
}
/**
......@@ -1712,7 +1712,7 @@ function hook_field_storage_load($entity_type, $entities, $age, $fields, $option
->fields('t')
->condition('entity_type', $entity_type)
->condition($load_current ? 'entity_id' : 'revision_id', $ids, 'IN')
->condition('language', field_available_languages($entity_type, $field), 'IN')
->condition('langcode', field_available_languages($entity_type, $field), 'IN')
->orderBy('delta');
if (empty($options['deleted'])) {
......@@ -1723,11 +1723,11 @@ function hook_field_storage_load($entity_type, $entities, $age, $fields, $option
$delta_count = array();
foreach ($results as $row) {
if (!isset($delta_count[$row->entity_id][$row->language])) {
$delta_count[$row->entity_id][$row->language] = 0;
if (!isset($delta_count[$row->entity_id][$row->langcode])) {
$delta_count[$row->entity_id][$row->langcode] = 0;
}
if ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || $delta_count[$row->entity_id][$row->language] < $field['cardinality']) {
if ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || $delta_count[$row->entity_id][$row->langcode] < $field['cardinality']) {
$item = array();
// For each column declared by the field, populate the item
// from the prefixed database column.
......@@ -1737,8 +1737,8 @@ function hook_field_storage_load($entity_type, $entities, $age, $fields, $option
}
// Add the item to the field values for the entity.
$entities[$row->entity_id]->{$field_name}[$row->language][] = $item;
$delta_count[$row->entity_id][$row->language]++;
$entities[$row->entity_id]->{$field_name}[$row->langcode][] = $item;
$delta_count[$row->entity_id][$row->langcode]++;
}
}
}
......@@ -1773,39 +1773,39 @@ function hook_field_storage_write($entity_type, $entity, $op, $fields) {
$table_name = _field_sql_storage_tablename($field);
$revision_name = _field_sql_storage_revision_tablename($field);
$all_languages = field_available_languages($entity_type, $field);
$field_languages = array_intersect($all_languages, array_keys((array) $entity->$field_name));
$all_langcodes = field_available_languages($entity_type, $field);
$field_langcodes = array_intersect($all_langcodes, array_keys((array) $entity->$field_name));
// Delete and insert, rather than update, in case a value was added.
if ($op == FIELD_STORAGE_UPDATE) {
// Delete languages present in the incoming $entity->$field_name.
// Delete all languages if $entity->$field_name is empty.
$languages = !empty($entity->$field_name) ? $field_languages : $all_languages;
if ($languages) {
// Delete language codes present in the incoming $entity->$field_name.
// Delete all language codes if $entity->$field_name is empty.
$langcodes = !empty($entity->$field_name) ? $field_langcodes : $all_langcodes;
if ($langcodes) {
db_delete($table_name)
->condition('entity_type', $entity_type)
->condition('entity_id', $id)
->condition('language', $languages, 'IN')
->condition('langcode', $langcodes, 'IN')
->execute();
db_delete($revision_name)
->condition('entity_type', $entity_type)
->condition('entity_id', $id)
->condition('revision_id', $vid)
->condition('language', $languages, 'IN')
->condition('langcode', $langcodes, 'IN')
->execute();
}
}
// Prepare the multi-insert query.
$do_insert = FALSE;
$columns = array('entity_type', 'entity_id', 'revision_id', 'bundle', 'delta', 'language');
$columns = array('entity_type', 'entity_id', 'revision_id', 'bundle', 'delta', 'langcode');
foreach ($field['columns'] as $column => $attributes) {
$columns[] = _field_sql_storage_columnname($field_name, $column);
}
$query = db_insert($table_name)->fields($columns);
$revision_query = db_insert($revision_name)->fields($columns);
foreach ($field_languages as $langcode) {
foreach ($field_langcodes as $langcode) {
$items = (array) $entity->{$field_name}[$langcode];
$delta_count = 0;
foreach ($items as $delta => $item) {
......@@ -1817,7 +1817,7 @@ function hook_field_storage_write($entity_type, $entity, $op, $fields) {
'revision_id' => $vid,
'bundle' => $bundle,
'delta' => $delta,
'language' => $langcode,
'langcode' => $langcode,
);
foreach ($field['columns'] as $column => $attributes) {
$record[_field_sql_storage_columnname($field_name, $column)] = isset($item[$column]) ? $item[$column] : NULL;
......@@ -1955,7 +1955,7 @@ function hook_field_storage_query($query) {
$sql_field = "$table_alias." . _field_sql_storage_columnname($field['field_name'], $condition['column']);
$query->addCondition($select_query, $sql_field, $condition);
// Add delta / language group conditions.
foreach (array('delta', 'language') as $column) {
foreach (array('delta', 'langcode') as $column) {
if (isset($condition[$column . '_group'])) {
$group_name = $condition[$column . '_group'];
if (!isset($groups[$column][$group_name])) {
......
......@@ -174,7 +174,7 @@ function __construct($errors) {
* - 'deleted': If TRUE, the function will operate on deleted fields
* as well as non-deleted fields. If unset or FALSE, only
* non-deleted fields are operated on.
* - 'language': A language code or an array of language codes keyed by field
* - 'langcode': A language code or an array of language codes keyed by field
* name. It will be used to narrow down to a single value the available
* languages to act on.
*/
......@@ -183,7 +183,7 @@ function _field_invoke($op, $entity_type, $entity, &$a = NULL, &$b = NULL, $opti
$default_options = array(
'default' => FALSE,
'deleted' => FALSE,
'language' => NULL,
'langcode' => NULL,
);
$options += $default_options;
......@@ -201,10 +201,10 @@ function _field_invoke($op, $entity_type, $entity, &$a = NULL, &$b = NULL, $opti
$function = $options['default'] ? 'field_default_' . $op : $field['module'] . '_field_' . $op;
if (function_exists($function)) {
// Determine the list of languages to iterate on.
$available_languages = field_available_languages($entity_type, $field);
$languages = _field_language_suggestion($available_languages, $options['language'], $field_name);
$available_langcodes = field_available_languages($entity_type, $field);
$langcodes = _field_language_suggestion($available_langcodes, $options['langcode'], $field_name);
foreach ($languages as $langcode) {
foreach ($langcodes as $langcode) {
$items = isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : array();
$result = $function($entity_type, $entity, $field, $instance, $langcode, $items, $a, $b);
if (isset($result)) {
......@@ -268,9 +268,9 @@ function _field_invoke($op, $entity_type, $entity, &$a = NULL, &$b = NULL, $opti
* - 'deleted': If TRUE, the function will operate on deleted fields
* as well as non-deleted fields. If unset or FALSE, only
* non-deleted fields are operated on.
* - 'language': A language code or an array of arrays of language codes keyed
* - 'langcode': A language code or an array of arrays of language codes keyed
* by entity id and field name. It will be used to narrow down to a single
* value the available languages to act on.
* value the available language codes to act on.
*
* @return
* An array of returned values keyed by entity id.
......@@ -280,7 +280,7 @@ function _field_invoke_multiple($op, $entity_type, $entities, &$a = NULL, &$b =
$default_options = array(
'default' => FALSE,
'deleted' => FALSE,
'language' => NULL,
'langcode' => NULL,
);
$options += $default_options;
$field_info = field_info_field_by_ids();
......@@ -316,12 +316,12 @@ function _field_invoke_multiple($op, $entity_type, $entities, &$a = NULL, &$b =
}
// Extract the field values into a separate variable, easily accessed
// by hook implementations.
// Unless a language suggestion is provided we iterate on all the
// available languages.
$available_languages = field_available_languages($entity_type, $field);
$language = !empty($options['language'][$id]) ? $options['language'][$id] : $options['language'];
$languages = _field_language_suggestion($available_languages, $language, $field_name);
foreach ($languages as $langcode) {
// Unless a language code suggestion is provided we iterate on all the
// available language codes.
$available_langcodes = field_available_languages($entity_type, $field);
$langcode = !empty($options['langcode'][$id]) ? $options['langcode'][$id] : $options['langcode'];
$langcodes = _field_language_suggestion($available_langcodes, $langcode, $field_name);
foreach ($langcodes as $langcode) {
$grouped_items[$field_id][$langcode][$id] = isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : array();
// Group the instances and entities corresponding to the current
// field.
......@@ -564,7 +564,7 @@ function field_attach_form($entity_type, $entity, &$form, &$form_state, $langcod
$form += array('#parents' => array());
// If no language is provided use the default site language.
$options = array('language' => field_valid_language($langcode));
$options = array('langcode' => field_valid_language($langcode));
$form += (array) _field_invoke_default('form', $entity_type, $entity, $form, $form_state, $options);
// Add custom weight handling.
......@@ -1095,7 +1095,7 @@ function field_attach_delete_revision($entity_type, $entity) {
* is provided the current language is used.
*/
function field_attach_prepare_view($entity_type, $entities, $view_mode, $langcode = NULL) {
$options = array('language' => array());
$options = array('langcode' => array());
// To ensure hooks are only run once per entity, only process items without
// the _field_view_prepared flag.
......@@ -1106,9 +1106,9 @@ function field_attach_prepare_view($entity_type, $entities, $view_mode, $langcod
// Add this entity to the items to be prepared.
$prepare[$id] = $entity;
// Determine the actual language to display for each field, given the
// languages available in the field data.
$options['language'][$id] = field_language($entity_type, $entity, NULL, $langcode);
// Determine the actual language code to display for each field, given the
// language codes available in the field data.
$options['langcode'][$id] = field_language($entity_type, $entity, NULL, $langcode);
// Mark this item as prepared.
$entity->_field_view_prepared = TRUE;
......@@ -1171,10 +1171,10 @@ function field_attach_prepare_view($entity_type, $entities, $view_mode, $langcod
* A renderable array for the field values.
*/
function field_attach_view($entity_type, $entity, $view_mode, $langcode = NULL) {
// Determine the actual language to display for each field, given the
// languages available in the field data.
$display_language = field_language($entity_type, $entity, NULL, $langcode);
$options = array('language' => $display_language);
// Determine the actual language code to display for each field, given the
// language codes available in the field data.
$display_langcode = field_language($entity_type, $entity, NULL, $langcode);
$options = array('langcode' => $display_langcode);
// Invoke field_default_view().
$null = NULL;
......@@ -1192,7 +1192,7 @@ function field_attach_view($entity_type, $entity, $view_mode, $langcode = NULL)
'entity' => $entity,
'view_mode' => $view_mode,
'display' => $view_mode,
'language' => $langcode,
'langcode' => $langcode,
);
drupal_alter('field_attach_view', $output, $context);
......@@ -1266,7 +1266,7 @@ function field_attach_preprocess($entity_type, $entity, $element, &$variables) {
* The source language from which translate.
*/
function field_attach_prepare_translation($entity_type, $entity, $langcode, $source_entity, $source_langcode) {
$options = array('language' => $langcode);
$options = array('langcode' => $langcode);
// Copy source field values into the entity to be prepared.
_field_invoke_default('prepare_translation', $entity_type, $entity, $source_entity, $source_langcode, $options);
// Let field types handle their own advanced translation pattern if needed.
......
......@@ -316,7 +316,7 @@ function _update_7000_field_delete_instance($field_name, $entity_type, $bundle)
* by the $key parameter.
* @ingroup update-api-7.x-to-8.x
*/
function _update_7000_field_read_fields(array $conditions = array(), $key = 'id') {
function _update_8000_field_read_fields(array $conditions = array(), $key = 'id') {
$fields = array();
$query = db_select('field_config', 'fc', array('fetch' => PDO::FETCH_ASSOC))
->fields('fc');
......
......@@ -867,10 +867,10 @@ function field_view_value($entity_type, $entity, $field_name, $item, $display =
* - weight: (float) The weight to assign to the renderable element.
* Defaults to 0.
* @param $langcode
* (Optional) The language the field values are to be shown in. The site's
* current language fallback logic will be applied no values are available
* for the language. If no language is provided the current language will be
* used.
* (Optional) The language code the field values are to be shown in. The
* site's current language fallback logic will be applied when no values are
* available for given language code. If no language code is provided the
* current language will be used.
* @return
* A renderable array for the field value.
*
......@@ -887,10 +887,10 @@ function field_view_field($entity_type, $entity, $field_name, $display = array()
// Hook invocations are done through the _field_invoke() functions in
// 'single field' mode, to reuse the language fallback logic.
// Determine the actual language to display for the field, given the
// languages available in the field data.
$display_language = field_language($entity_type, $entity, $field_name, $langcode);
$options = array('field_name' => $field_name, 'language' => $display_language);
// Determine the actual language code to display for the field, given the
// language codes available in the field data.
$display_langcode = field_language($entity_type, $entity, $field_name, $langcode);
$options = array('field_name' => $field_name, 'langcode' => $display_langcode);
$null = NULL;
// Invoke prepare_view steps if needed.
......
......@@ -15,8 +15,8 @@
* @code
* $entity->{$field_name}[$langcode][$delta][$column_name]
* @endcode
* Every field can hold a single or multiple value for each language belonging
* to the available languages set:
* Every field can hold a single or multiple value for each language code
* belonging to the available language codes set:
* - For untranslatable fields this set only contains LANGUAGE_NOT_SPECIFIED.
* - For translatable fields this set can contain any language code. By default
* it is the list returned by field_content_languages(), which contains all
......@@ -24,7 +24,7 @@
* default can be altered by modules implementing
* hook_field_available_languages_alter().
*
* The available languages for a particular field are returned by
* The available language codes for a particular field are returned by
* field_available_languages(). Whether a field is translatable is determined by
* calling field_is_translatable(), which checks the $field['translatable']
* property returned by field_info_field(), and whether there is at least one
......@@ -33,12 +33,12 @@
* translations.
*
* By default, _field_invoke() and _field_invoke_multiple() are processing a
* field in all available languages, unless they are given a language
* field in all available languages, unless they are given a language code
* suggestion. Based on that suggestion, _field_language_suggestion() determines
* the languages to act on.
*
* Most field_attach_*() functions act on all available languages, except for
* the following:
* Most field_attach_*() functions act on all available language codes, except
* for the following:
* - field_attach_form() only takes a single language code, specifying which
* language the field values will be submitted in.
* - field_attach_view() requires the language the entity will be displayed in.
......@@ -85,11 +85,11 @@ function field_language_delete() {
}
/**
* Collects the available languages for the given entity type and field.
* Collects the available language codes 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_NOT_SPECIFIED will be
* returned. Since the default value for a 'translatable' entity property is
* 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.
*
......@@ -104,38 +104,39 @@ function field_language_delete() {
function field_available_languages($entity_type, $field) {
static $drupal_static_fast;
if (!isset($drupal_static_fast)) {
$drupal_static_fast['field_languages'] = &drupal_static(__FUNCTION__);
$drupal_static_fast['field_langcodes'] = &drupal_static(__FUNCTION__);
}
$field_languages = &$drupal_static_fast['field_languages'];
$field_langcodes = &$drupal_static_fast['field_langcodes'];
$field_name = $field['field_name'];
if (!isset($field_languages[$entity_type][$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)) {
$languages = field_content_languages();
$langcodes = 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;
drupal_alter('field_available_languages', $langcodes, $context);
$field_langcodes[$entity_type][$field_name] = $langcodes;
}
else {
$field_languages[$entity_type][$field_name] = array(LANGUAGE_NOT_SPECIFIED);
$field_langcodes[$entity_type][$field_name] = array(LANGUAGE_NOT_SPECIFIED);
}
}
return $field_languages[$entity_type][$field_name];
return $field_langcodes[$entity_type][$field_name];
}
/**
* Process the given language suggestion based on the available languages.
* Process the given language code suggestion based on the available language
* codes.
*
* If a non-empty language suggestion is provided it must appear among the
* available languages, otherwise it will be ignored.
* If a non-empty language code suggestion is provided it must appear among the
* available language codes, otherwise it will be ignored.
*
* @param $available_languages
* @param $available_langcodes
* An array of valid language codes.
* @param $language_suggestion
* @param $langcode_suggestion
* A language code or an array of language codes keyed by field name.
* @param $field_name
* The name of the field being processed.
......@@ -143,28 +144,28 @@ function field_available_languages($entity_type, $field) {
* @return
* An array of valid language codes.
*/
function _field_language_suggestion($available_languages, $language_suggestion, $field_name) {
function _field_language_suggestion($available_langcodes, $langcode_suggestion, $field_name) {
// Handle possible language suggestions.
if (!empty($language_suggestion)) {
if (!empty($langcode_suggestion)) {
// We might have an array of language suggestions keyed by field name.
if (is_array($language_suggestion) && isset($language_suggestion[$field_name])) {
$language_suggestion = $language_suggestion[$field_name];
if (is_array($langcode_suggestion) && isset($langcode_suggestion[$field_name])) {
$langcode_suggestion = $langcode_suggestion[$field_name];
}
// If we have a language suggestion and the suggested language is available,
// we return only it.
if (in_array($language_suggestion, $available_languages)) {
$available_languages = array($language_suggestion);
// If we have a single language code suggestion and it is available, we just
// return it.
if (in_array($langcode_suggestion, $available_langcodes)) {
$available_langcodes = array($langcode_suggestion);
}
}
return $available_languages;
return $available_langcodes;
}
/**
* Returns available content languages.
* Returns available content language codes.
*
* The languages that may be associated to fields include
* The language codes that may be associated to fields include
* LANGUAGE_NOT_SPECIFIED.
*
* @return
......@@ -229,9 +230,9 @@ function field_has_translation_handler($entity_type, $handler = NULL) {
/**
* Ensures that a given language code is valid.
*
* Checks whether the given language is one of the enabled languages. Otherwise,
* it returns the current, global language; or the site's default language, if
* the additional parameter $default is TRUE.
* Checks whether the given language code is one of the enabled language codes.
* Otherwise, it returns the current, global language code; or the site's
* default language code, if the additional parameter $default is TRUE.
*
* @param $langcode
* The language code to validate.
......@@ -251,16 +252,18 @@ function field_valid_language($langcode, $default = TRUE) {
}
/**
* Returns the display language for the fields attached to the given entity.
* Returns the display language code for the fields attached to the given
* entity.
*
* The actual language for each given field is determined based on the requested
* language and the actual data available in the fields themselves.
* The actual language code for each given field is determined based on the
* requested language code and the actual data available in the fields
* themselves.
* If there is no registered translation handler for the given entity type, the
* display language to be used is just LANGUAGE_NOT_SPECIFIED, as no other
* display language code to be used is just LANGUAGE_NOT_SPECIFIED, as no other