- Patch #1439692 by clemens.tolboom, plach, dawehner, das-peter, Gábor Hojtsy: Rename field language properties to langcode.
							parent
							
								
									99d9ca8e44
								
							
						
					
					
						commit
						47556803a8
					
				| 
						 | 
					@ -265,9 +265,9 @@ class EntityFieldQuery {
 | 
				
			||||||
   * @param $delta_group
 | 
					   * @param $delta_group
 | 
				
			||||||
   *   An arbitrary identifier: conditions in the same group must have the same
 | 
					   *   An arbitrary identifier: conditions in the same group must have the same
 | 
				
			||||||
   *   $delta_group.
 | 
					   *   $delta_group.
 | 
				
			||||||
   * @param $language_group
 | 
					   * @param $langcode_group
 | 
				
			||||||
   *   An arbitrary identifier: conditions in the same group must have the same
 | 
					   *   An arbitrary identifier: conditions in the same group must have the same
 | 
				
			||||||
   *   $language_group.
 | 
					   *   $langcode_group.
 | 
				
			||||||
   *
 | 
					   *
 | 
				
			||||||
   * @return EntityFieldQuery
 | 
					   * @return EntityFieldQuery
 | 
				
			||||||
   *   The called object.
 | 
					   *   The called object.
 | 
				
			||||||
| 
						 | 
					@ -275,8 +275,8 @@ class EntityFieldQuery {
 | 
				
			||||||
   * @see EntityFieldQuery::addFieldCondition
 | 
					   * @see EntityFieldQuery::addFieldCondition
 | 
				
			||||||
   * @see EntityFieldQuery::deleted
 | 
					   * @see EntityFieldQuery::deleted
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  public function fieldCondition($field, $column = NULL, $value = NULL, $operator = NULL, $delta_group = NULL, $language_group = NULL) {
 | 
					  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, $language_group);
 | 
					    return $this->addFieldCondition($this->fieldConditions, $field, $column, $value, $operator, $delta_group, $langcode_group);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
| 
						 | 
					@ -291,9 +291,9 @@ class EntityFieldQuery {
 | 
				
			||||||
   * @param $delta_group
 | 
					   * @param $delta_group
 | 
				
			||||||
   *   An arbitrary identifier: conditions in the same group must have the same
 | 
					   *   An arbitrary identifier: conditions in the same group must have the same
 | 
				
			||||||
   *   $delta_group.
 | 
					   *   $delta_group.
 | 
				
			||||||
   * @param $language_group
 | 
					   * @param $langcode_group
 | 
				
			||||||
   *   An arbitrary identifier: conditions in the same group must have the same
 | 
					   *   An arbitrary identifier: conditions in the same group must have the same
 | 
				
			||||||
   *   $language_group.
 | 
					   *   $langcode_group.
 | 
				
			||||||
   *
 | 
					   *
 | 
				
			||||||
   * @return EntityFieldQuery
 | 
					   * @return EntityFieldQuery
 | 
				
			||||||
   *   The called object.
 | 
					   *   The called object.
 | 
				
			||||||
| 
						 | 
					@ -301,8 +301,8 @@ class EntityFieldQuery {
 | 
				
			||||||
   * @see EntityFieldQuery::addFieldCondition
 | 
					   * @see EntityFieldQuery::addFieldCondition
 | 
				
			||||||
   * @see EntityFieldQuery::deleted
 | 
					   * @see EntityFieldQuery::deleted
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  public function fieldLanguageCondition($field, $value = NULL, $operator = NULL, $delta_group = NULL, $language_group = NULL) {
 | 
					  public function fieldLanguageCondition($field, $value = NULL, $operator = NULL, $delta_group = NULL, $langcode_group = NULL) {
 | 
				
			||||||
    return $this->addFieldCondition($this->fieldMetaConditions, $field, 'language', $value, $operator, $delta_group, $language_group);
 | 
					    return $this->addFieldCondition($this->fieldMetaConditions, $field, 'langcode', $value, $operator, $delta_group, $langcode_group);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
| 
						 | 
					@ -317,9 +317,9 @@ class EntityFieldQuery {
 | 
				
			||||||
   * @param $delta_group
 | 
					   * @param $delta_group
 | 
				
			||||||
   *   An arbitrary identifier: conditions in the same group must have the same
 | 
					   *   An arbitrary identifier: conditions in the same group must have the same
 | 
				
			||||||
   *   $delta_group.
 | 
					   *   $delta_group.
 | 
				
			||||||
   * @param $language_group
 | 
					   * @param $langcode_group
 | 
				
			||||||
   *   An arbitrary identifier: conditions in the same group must have the same
 | 
					   *   An arbitrary identifier: conditions in the same group must have the same
 | 
				
			||||||
   *   $language_group.
 | 
					   *   $langcode_group.
 | 
				
			||||||
   *
 | 
					   *
 | 
				
			||||||
   * @return EntityFieldQuery
 | 
					   * @return EntityFieldQuery
 | 
				
			||||||
   *   The called object.
 | 
					   *   The called object.
 | 
				
			||||||
| 
						 | 
					@ -327,8 +327,8 @@ class EntityFieldQuery {
 | 
				
			||||||
   * @see EntityFieldQuery::addFieldCondition
 | 
					   * @see EntityFieldQuery::addFieldCondition
 | 
				
			||||||
   * @see EntityFieldQuery::deleted
 | 
					   * @see EntityFieldQuery::deleted
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  public function fieldDeltaCondition($field, $value = NULL, $operator = NULL, $delta_group = NULL, $language_group = NULL) {
 | 
					  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, $language_group);
 | 
					    return $this->addFieldCondition($this->fieldMetaConditions, $field, 'delta', $value, $operator, $delta_group, $langcode_group);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
| 
						 | 
					@ -367,14 +367,14 @@ class EntityFieldQuery {
 | 
				
			||||||
   *   against any combination of deltas. By passing the conditions with the
 | 
					   *   against any combination of deltas. By passing the conditions with the
 | 
				
			||||||
   *   same $delta_group it will ensure that only values attached to the same
 | 
					   *   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.
 | 
					   *   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
 | 
					   *   An arbitrary identifier: conditions in the same group must have the same
 | 
				
			||||||
   *   $language_group.
 | 
					   *   $langcode_group.
 | 
				
			||||||
   *
 | 
					   *
 | 
				
			||||||
   * @return EntityFieldQuery
 | 
					   * @return EntityFieldQuery
 | 
				
			||||||
   *   The called object.
 | 
					   *   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)) {
 | 
					    if (is_scalar($field)) {
 | 
				
			||||||
      $field_definition = field_info_field($field);
 | 
					      $field_definition = field_info_field($field);
 | 
				
			||||||
      if (empty($field_definition)) {
 | 
					      if (empty($field_definition)) {
 | 
				
			||||||
| 
						 | 
					@ -392,7 +392,7 @@ class EntityFieldQuery {
 | 
				
			||||||
        'value' => $value,
 | 
					        'value' => $value,
 | 
				
			||||||
        'operator' => $operator,
 | 
					        'operator' => $operator,
 | 
				
			||||||
        'delta_group' => $delta_group,
 | 
					        'delta_group' => $delta_group,
 | 
				
			||||||
        'language_group' => $language_group,
 | 
					        'langcode_group' => $langcode_group,
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return $this;
 | 
					    return $this;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1526,7 +1526,9 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
 | 
				
			||||||
        sort($results);
 | 
					        sort($results);
 | 
				
			||||||
        sort($intended_results);
 | 
					        sort($intended_results);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      $this->assertEqual($results, $intended_results, $message);
 | 
					      if (!$this->assertEqual($results, $intended_results, $message)) {
 | 
				
			||||||
 | 
					        debug($results, $message);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    catch (Exception $e) {
 | 
					    catch (Exception $e) {
 | 
				
			||||||
      $this->fail('Exception thrown: '. $e->getMessage());
 | 
					      $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.
 | 
					 * Perform alterations on field_language() values.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This hook is invoked to alter the array of display languages for the given
 | 
					 * This hook is invoked to alter the array of display language codes for the
 | 
				
			||||||
 * entity.
 | 
					 * given entity.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @param $display_language
 | 
					 * @param $display_langcode
 | 
				
			||||||
 *   A reference to an array of language codes keyed by field name.
 | 
					 *   A reference to an array of language codes keyed by field name.
 | 
				
			||||||
 * @param $context
 | 
					 * @param $context
 | 
				
			||||||
 *   An associative array containing:
 | 
					 *   An associative array containing:
 | 
				
			||||||
| 
						 | 
					@ -1470,11 +1470,11 @@ function hook_field_attach_prepare_translation_alter(&$entity, $context) {
 | 
				
			||||||
 *   - entity: The entity with fields to render.
 | 
					 *   - entity: The entity with fields to render.
 | 
				
			||||||
 *   - langcode: The language code $entity has to be displayed in.
 | 
					 *   - 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
 | 
					  // Do not apply core language fallback rules if they are disabled or if Locale
 | 
				
			||||||
  // is not registered as a translation handler.
 | 
					  // is not registered as a translation handler.
 | 
				
			||||||
  if (variable_get('locale_field_language_fallback', TRUE) && field_has_translation_handler($context['entity_type'], 'locale')) {
 | 
					  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.
 | 
					 * Alter field_available_languages() values.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This hook is invoked from field_available_languages() to allow modules to
 | 
					 * 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.
 | 
					 *   A reference to an array of language codes to be made available.
 | 
				
			||||||
 * @param $context
 | 
					 * @param $context
 | 
				
			||||||
 *   An associative array containing:
 | 
					 *   An associative array containing:
 | 
				
			||||||
 *   - entity_type: The type of the entity the field is attached to.
 | 
					 *   - entity_type: The type of the entity the field is attached to.
 | 
				
			||||||
 *   - field: A field data structure.
 | 
					 *   - field: A field data structure.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function hook_field_available_languages_alter(&$languages, $context) {
 | 
					function hook_field_available_languages_alter(&$langcodes, $context) {
 | 
				
			||||||
  // Add an unavailable language.
 | 
					  // Add an unavailable language code.
 | 
				
			||||||
  $languages[] = 'xx';
 | 
					  $langcodes[] = 'xx';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Remove an available language.
 | 
					  // Remove an available language code.
 | 
				
			||||||
  $index = array_search('yy', $languages);
 | 
					  $index = array_search('yy', $langcodes);
 | 
				
			||||||
  unset($languages[$index]);
 | 
					  unset($langcodes[$index]);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
| 
						 | 
					@ -1712,7 +1712,7 @@ function hook_field_storage_load($entity_type, $entities, $age, $fields, $option
 | 
				
			||||||
      ->fields('t')
 | 
					      ->fields('t')
 | 
				
			||||||
      ->condition('entity_type', $entity_type)
 | 
					      ->condition('entity_type', $entity_type)
 | 
				
			||||||
      ->condition($load_current ? 'entity_id' : 'revision_id', $ids, 'IN')
 | 
					      ->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');
 | 
					      ->orderBy('delta');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (empty($options['deleted'])) {
 | 
					    if (empty($options['deleted'])) {
 | 
				
			||||||
| 
						 | 
					@ -1723,11 +1723,11 @@ function hook_field_storage_load($entity_type, $entities, $age, $fields, $option
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $delta_count = array();
 | 
					    $delta_count = array();
 | 
				
			||||||
    foreach ($results as $row) {
 | 
					    foreach ($results as $row) {
 | 
				
			||||||
      if (!isset($delta_count[$row->entity_id][$row->language])) {
 | 
					      if (!isset($delta_count[$row->entity_id][$row->langcode])) {
 | 
				
			||||||
        $delta_count[$row->entity_id][$row->language] = 0;
 | 
					        $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();
 | 
					        $item = array();
 | 
				
			||||||
        // For each column declared by the field, populate the item
 | 
					        // For each column declared by the field, populate the item
 | 
				
			||||||
        // from the prefixed database column.
 | 
					        // 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.
 | 
					        // Add the item to the field values for the entity.
 | 
				
			||||||
        $entities[$row->entity_id]->{$field_name}[$row->language][] = $item;
 | 
					        $entities[$row->entity_id]->{$field_name}[$row->langcode][] = $item;
 | 
				
			||||||
        $delta_count[$row->entity_id][$row->language]++;
 | 
					        $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);
 | 
					    $table_name = _field_sql_storage_tablename($field);
 | 
				
			||||||
    $revision_name = _field_sql_storage_revision_tablename($field);
 | 
					    $revision_name = _field_sql_storage_revision_tablename($field);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $all_languages = field_available_languages($entity_type, $field);
 | 
					    $all_langcodes = field_available_languages($entity_type, $field);
 | 
				
			||||||
    $field_languages = array_intersect($all_languages, array_keys((array) $entity->$field_name));
 | 
					    $field_langcodes = array_intersect($all_langcodes, array_keys((array) $entity->$field_name));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Delete and insert, rather than update, in case a value was added.
 | 
					    // Delete and insert, rather than update, in case a value was added.
 | 
				
			||||||
    if ($op == FIELD_STORAGE_UPDATE) {
 | 
					    if ($op == FIELD_STORAGE_UPDATE) {
 | 
				
			||||||
      // Delete languages present in the incoming $entity->$field_name.
 | 
					      // Delete language codes present in the incoming $entity->$field_name.
 | 
				
			||||||
      // Delete all languages if $entity->$field_name is empty.
 | 
					      // Delete all language codes if $entity->$field_name is empty.
 | 
				
			||||||
      $languages = !empty($entity->$field_name) ? $field_languages : $all_languages;
 | 
					      $langcodes = !empty($entity->$field_name) ? $field_langcodes : $all_langcodes;
 | 
				
			||||||
      if ($languages) {
 | 
					      if ($langcodes) {
 | 
				
			||||||
        db_delete($table_name)
 | 
					        db_delete($table_name)
 | 
				
			||||||
          ->condition('entity_type', $entity_type)
 | 
					          ->condition('entity_type', $entity_type)
 | 
				
			||||||
          ->condition('entity_id', $id)
 | 
					          ->condition('entity_id', $id)
 | 
				
			||||||
          ->condition('language', $languages, 'IN')
 | 
					          ->condition('langcode', $langcodes, 'IN')
 | 
				
			||||||
          ->execute();
 | 
					          ->execute();
 | 
				
			||||||
        db_delete($revision_name)
 | 
					        db_delete($revision_name)
 | 
				
			||||||
          ->condition('entity_type', $entity_type)
 | 
					          ->condition('entity_type', $entity_type)
 | 
				
			||||||
          ->condition('entity_id', $id)
 | 
					          ->condition('entity_id', $id)
 | 
				
			||||||
          ->condition('revision_id', $vid)
 | 
					          ->condition('revision_id', $vid)
 | 
				
			||||||
          ->condition('language', $languages, 'IN')
 | 
					          ->condition('langcode', $langcodes, 'IN')
 | 
				
			||||||
          ->execute();
 | 
					          ->execute();
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Prepare the multi-insert query.
 | 
					    // Prepare the multi-insert query.
 | 
				
			||||||
    $do_insert = FALSE;
 | 
					    $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) {
 | 
					    foreach ($field['columns'] as $column => $attributes) {
 | 
				
			||||||
      $columns[] = _field_sql_storage_columnname($field_name, $column);
 | 
					      $columns[] = _field_sql_storage_columnname($field_name, $column);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    $query = db_insert($table_name)->fields($columns);
 | 
					    $query = db_insert($table_name)->fields($columns);
 | 
				
			||||||
    $revision_query = db_insert($revision_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];
 | 
					      $items = (array) $entity->{$field_name}[$langcode];
 | 
				
			||||||
      $delta_count = 0;
 | 
					      $delta_count = 0;
 | 
				
			||||||
      foreach ($items as $delta => $item) {
 | 
					      foreach ($items as $delta => $item) {
 | 
				
			||||||
| 
						 | 
					@ -1817,7 +1817,7 @@ function hook_field_storage_write($entity_type, $entity, $op, $fields) {
 | 
				
			||||||
          'revision_id' => $vid,
 | 
					          'revision_id' => $vid,
 | 
				
			||||||
          'bundle' => $bundle,
 | 
					          'bundle' => $bundle,
 | 
				
			||||||
          'delta' => $delta,
 | 
					          'delta' => $delta,
 | 
				
			||||||
          'language' => $langcode,
 | 
					          'langcode' => $langcode,
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
        foreach ($field['columns'] as $column => $attributes) {
 | 
					        foreach ($field['columns'] as $column => $attributes) {
 | 
				
			||||||
          $record[_field_sql_storage_columnname($field_name, $column)] = isset($item[$column]) ? $item[$column] : NULL;
 | 
					          $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']);
 | 
					    $sql_field = "$table_alias." . _field_sql_storage_columnname($field['field_name'], $condition['column']);
 | 
				
			||||||
    $query->addCondition($select_query, $sql_field, $condition);
 | 
					    $query->addCondition($select_query, $sql_field, $condition);
 | 
				
			||||||
    // Add delta / language group conditions.
 | 
					    // Add delta / language group conditions.
 | 
				
			||||||
    foreach (array('delta', 'language') as $column) {
 | 
					    foreach (array('delta', 'langcode') as $column) {
 | 
				
			||||||
      if (isset($condition[$column . '_group'])) {
 | 
					      if (isset($condition[$column . '_group'])) {
 | 
				
			||||||
        $group_name = $condition[$column . '_group'];
 | 
					        $group_name = $condition[$column . '_group'];
 | 
				
			||||||
        if (!isset($groups[$column][$group_name])) {
 | 
					        if (!isset($groups[$column][$group_name])) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -174,7 +174,7 @@ const FIELD_STORAGE_INSERT = 'insert';
 | 
				
			||||||
 *  - 'deleted': If TRUE, the function will operate on deleted fields
 | 
					 *  - 'deleted': If TRUE, the function will operate on deleted fields
 | 
				
			||||||
 *    as well as non-deleted fields. If unset or FALSE, only
 | 
					 *    as well as non-deleted fields. If unset or FALSE, only
 | 
				
			||||||
 *    non-deleted fields are operated on.
 | 
					 *    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
 | 
					 *    name. It will be used to narrow down to a single value the available
 | 
				
			||||||
 *    languages to act on.
 | 
					 *    languages to act on.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
| 
						 | 
					@ -183,7 +183,7 @@ function _field_invoke($op, $entity_type, $entity, &$a = NULL, &$b = NULL, $opti
 | 
				
			||||||
  $default_options = array(
 | 
					  $default_options = array(
 | 
				
			||||||
    'default' => FALSE,
 | 
					    'default' => FALSE,
 | 
				
			||||||
    'deleted' => FALSE,
 | 
					    'deleted' => FALSE,
 | 
				
			||||||
    'language' => NULL,
 | 
					    'langcode' => NULL,
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
  $options += $default_options;
 | 
					  $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;
 | 
					    $function = $options['default'] ? 'field_default_' . $op : $field['module'] . '_field_' . $op;
 | 
				
			||||||
    if (function_exists($function)) {
 | 
					    if (function_exists($function)) {
 | 
				
			||||||
      // Determine the list of languages to iterate on.
 | 
					      // Determine the list of languages to iterate on.
 | 
				
			||||||
      $available_languages = field_available_languages($entity_type, $field);
 | 
					      $available_langcodes = field_available_languages($entity_type, $field);
 | 
				
			||||||
      $languages = _field_language_suggestion($available_languages, $options['language'], $field_name);
 | 
					      $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();
 | 
					        $items = isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : array();
 | 
				
			||||||
        $result = $function($entity_type, $entity, $field, $instance, $langcode, $items, $a, $b);
 | 
					        $result = $function($entity_type, $entity, $field, $instance, $langcode, $items, $a, $b);
 | 
				
			||||||
        if (isset($result)) {
 | 
					        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
 | 
					 *  - 'deleted': If TRUE, the function will operate on deleted fields
 | 
				
			||||||
 *    as well as non-deleted fields. If unset or FALSE, only
 | 
					 *    as well as non-deleted fields. If unset or FALSE, only
 | 
				
			||||||
 *    non-deleted fields are operated on.
 | 
					 *    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
 | 
					 *    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
 | 
					 * @return
 | 
				
			||||||
 *   An array of returned values keyed by entity id.
 | 
					 *   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_options = array(
 | 
				
			||||||
    'default' => FALSE,
 | 
					    'default' => FALSE,
 | 
				
			||||||
    'deleted' => FALSE,
 | 
					    'deleted' => FALSE,
 | 
				
			||||||
    'language' => NULL,
 | 
					    'langcode' => NULL,
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
  $options += $default_options;
 | 
					  $options += $default_options;
 | 
				
			||||||
  $field_info = field_info_field_by_ids();
 | 
					  $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
 | 
					        // Extract the field values into a separate variable, easily accessed
 | 
				
			||||||
        // by hook implementations.
 | 
					        // by hook implementations.
 | 
				
			||||||
        // Unless a language suggestion is provided we iterate on all the
 | 
					        // Unless a language code suggestion is provided we iterate on all the
 | 
				
			||||||
        // available languages.
 | 
					        // available language codes.
 | 
				
			||||||
        $available_languages = field_available_languages($entity_type, $field);
 | 
					        $available_langcodes = field_available_languages($entity_type, $field);
 | 
				
			||||||
        $language = !empty($options['language'][$id]) ? $options['language'][$id] : $options['language'];
 | 
					        $langcode = !empty($options['langcode'][$id]) ? $options['langcode'][$id] : $options['langcode'];
 | 
				
			||||||
        $languages = _field_language_suggestion($available_languages, $language, $field_name);
 | 
					        $langcodes = _field_language_suggestion($available_langcodes, $langcode, $field_name);
 | 
				
			||||||
        foreach ($languages as $langcode) {
 | 
					        foreach ($langcodes as $langcode) {
 | 
				
			||||||
          $grouped_items[$field_id][$langcode][$id] = isset($entity->{$field_name}[$langcode]) ? $entity->{$field_name}[$langcode] : array();
 | 
					          $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
 | 
					          // Group the instances and entities corresponding to the current
 | 
				
			||||||
          // field.
 | 
					          // field.
 | 
				
			||||||
| 
						 | 
					@ -564,7 +564,7 @@ function field_attach_form($entity_type, $entity, &$form, &$form_state, $langcod
 | 
				
			||||||
  $form += array('#parents' => array());
 | 
					  $form += array('#parents' => array());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // If no language is provided use the default site language.
 | 
					  // 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);
 | 
					  $form += (array) _field_invoke_default('form', $entity_type, $entity, $form, $form_state, $options);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Add custom weight handling.
 | 
					  // Add custom weight handling.
 | 
				
			||||||
| 
						 | 
					@ -1095,7 +1095,7 @@ function field_attach_delete_revision($entity_type, $entity) {
 | 
				
			||||||
 *   is provided the current language is used.
 | 
					 *   is provided the current language is used.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function field_attach_prepare_view($entity_type, $entities, $view_mode, $langcode = NULL) {
 | 
					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
 | 
					  // To ensure hooks are only run once per entity, only process items without
 | 
				
			||||||
  // the _field_view_prepared flag.
 | 
					  // 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.
 | 
					      // Add this entity to the items to be prepared.
 | 
				
			||||||
      $prepare[$id] = $entity;
 | 
					      $prepare[$id] = $entity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // Determine the actual language to display for each field, given the
 | 
					      // Determine the actual language code to display for each field, given the
 | 
				
			||||||
      // languages available in the field data.
 | 
					      // language codes available in the field data.
 | 
				
			||||||
      $options['language'][$id] = field_language($entity_type, $entity, NULL, $langcode);
 | 
					      $options['langcode'][$id] = field_language($entity_type, $entity, NULL, $langcode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // Mark this item as prepared.
 | 
					      // Mark this item as prepared.
 | 
				
			||||||
      $entity->_field_view_prepared = TRUE;
 | 
					      $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.
 | 
					 *   A renderable array for the field values.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function field_attach_view($entity_type, $entity, $view_mode, $langcode = NULL) {
 | 
					function field_attach_view($entity_type, $entity, $view_mode, $langcode = NULL) {
 | 
				
			||||||
  // Determine the actual language to display for each field, given the
 | 
					  // Determine the actual language code to display for each field, given the
 | 
				
			||||||
  // languages available in the field data.
 | 
					  // language codes available in the field data.
 | 
				
			||||||
  $display_language = field_language($entity_type, $entity, NULL, $langcode);
 | 
					  $display_langcode = field_language($entity_type, $entity, NULL, $langcode);
 | 
				
			||||||
  $options = array('language' => $display_language);
 | 
					  $options = array('langcode' => $display_langcode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Invoke field_default_view().
 | 
					  // Invoke field_default_view().
 | 
				
			||||||
  $null = NULL;
 | 
					  $null = NULL;
 | 
				
			||||||
| 
						 | 
					@ -1192,7 +1192,7 @@ function field_attach_view($entity_type, $entity, $view_mode, $langcode = NULL)
 | 
				
			||||||
    'entity' => $entity,
 | 
					    'entity' => $entity,
 | 
				
			||||||
    'view_mode' => $view_mode,
 | 
					    'view_mode' => $view_mode,
 | 
				
			||||||
    'display' => $view_mode,
 | 
					    'display' => $view_mode,
 | 
				
			||||||
    'language' => $langcode,
 | 
					    'langcode' => $langcode,
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
  drupal_alter('field_attach_view', $output, $context);
 | 
					  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.
 | 
					 *   The source language from which translate.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function field_attach_prepare_translation($entity_type, $entity, $langcode, $source_entity, $source_langcode) {
 | 
					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.
 | 
					  // Copy source field values into the entity to be prepared.
 | 
				
			||||||
  _field_invoke_default('prepare_translation', $entity_type, $entity, $source_entity, $source_langcode, $options);
 | 
					  _field_invoke_default('prepare_translation', $entity_type, $entity, $source_entity, $source_langcode, $options);
 | 
				
			||||||
  // Let field types handle their own advanced translation pattern if needed.
 | 
					  // 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.
 | 
					 *   by the $key parameter.
 | 
				
			||||||
 * @ingroup update-api-7.x-to-8.x
 | 
					 * @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();
 | 
					  $fields = array();
 | 
				
			||||||
  $query = db_select('field_config', 'fc', array('fetch' => PDO::FETCH_ASSOC))
 | 
					  $query = db_select('field_config', 'fc', array('fetch' => PDO::FETCH_ASSOC))
 | 
				
			||||||
    ->fields('fc');
 | 
					    ->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.
 | 
					 *     - weight: (float) The weight to assign to the renderable element.
 | 
				
			||||||
 *       Defaults to 0.
 | 
					 *       Defaults to 0.
 | 
				
			||||||
 * @param $langcode
 | 
					 * @param $langcode
 | 
				
			||||||
 *   (Optional) The language the field values are to be shown in. The site's
 | 
					 *   (Optional) The language code the field values are to be shown in. The
 | 
				
			||||||
 *   current language fallback logic will be applied no values are available
 | 
					 *   site's current language fallback logic will be applied when no values are
 | 
				
			||||||
 *   for the language. If no language is provided the current language will be
 | 
					 *   available for given language code. If no language code is provided the
 | 
				
			||||||
 *   used.
 | 
					 *   current language will be used.
 | 
				
			||||||
 * @return
 | 
					 * @return
 | 
				
			||||||
 *   A renderable array for the field value.
 | 
					 *   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
 | 
					    // Hook invocations are done through the _field_invoke() functions in
 | 
				
			||||||
    // 'single field' mode, to reuse the language fallback logic.
 | 
					    // 'single field' mode, to reuse the language fallback logic.
 | 
				
			||||||
    // Determine the actual language to display for the field, given the
 | 
					    // Determine the actual language code to display for the field, given the
 | 
				
			||||||
    // languages available in the field data.
 | 
					    // language codes available in the field data.
 | 
				
			||||||
    $display_language = field_language($entity_type, $entity, $field_name, $langcode);
 | 
					    $display_langcode = field_language($entity_type, $entity, $field_name, $langcode);
 | 
				
			||||||
    $options = array('field_name' => $field_name, 'language' => $display_language);
 | 
					    $options = array('field_name' => $field_name, 'langcode' => $display_langcode);
 | 
				
			||||||
    $null = NULL;
 | 
					    $null = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Invoke prepare_view steps if needed.
 | 
					    // Invoke prepare_view steps if needed.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,8 +15,8 @@
 | 
				
			||||||
 * @code
 | 
					 * @code
 | 
				
			||||||
 * $entity->{$field_name}[$langcode][$delta][$column_name]
 | 
					 * $entity->{$field_name}[$langcode][$delta][$column_name]
 | 
				
			||||||
 * @endcode
 | 
					 * @endcode
 | 
				
			||||||
 * Every field can hold a single or multiple value for each language belonging
 | 
					 * Every field can hold a single or multiple value for each language code
 | 
				
			||||||
 * to the available languages set:
 | 
					 * belonging to the available language codes set:
 | 
				
			||||||
 * - For untranslatable fields this set only contains LANGUAGE_NOT_SPECIFIED.
 | 
					 * - For untranslatable fields this set only contains LANGUAGE_NOT_SPECIFIED.
 | 
				
			||||||
 * - For translatable fields this set can contain any language code. By default
 | 
					 * - For translatable fields this set can contain any language code. By default
 | 
				
			||||||
 *   it is the list returned by field_content_languages(), which contains all
 | 
					 *   it is the list returned by field_content_languages(), which contains all
 | 
				
			||||||
| 
						 | 
					@ -24,7 +24,7 @@
 | 
				
			||||||
 *   default can be altered by modules implementing
 | 
					 *   default can be altered by modules implementing
 | 
				
			||||||
 *   hook_field_available_languages_alter().
 | 
					 *   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
 | 
					 * field_available_languages(). Whether a field is translatable is determined by
 | 
				
			||||||
 * calling field_is_translatable(), which checks the $field['translatable']
 | 
					 * calling field_is_translatable(), which checks the $field['translatable']
 | 
				
			||||||
 * property returned by field_info_field(), and whether there is at least one
 | 
					 * property returned by field_info_field(), and whether there is at least one
 | 
				
			||||||
| 
						 | 
					@ -33,12 +33,12 @@
 | 
				
			||||||
 * translations.
 | 
					 * translations.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * By default, _field_invoke() and _field_invoke_multiple() are processing a
 | 
					 * 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
 | 
					 * suggestion. Based on that suggestion, _field_language_suggestion() determines
 | 
				
			||||||
 * the languages to act on.
 | 
					 * the languages to act on.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Most field_attach_*() functions act on all available languages, except for
 | 
					 * Most field_attach_*() functions act on all available language codes, except
 | 
				
			||||||
 * the following:
 | 
					 * for the following:
 | 
				
			||||||
 * - field_attach_form() only takes a single language code, specifying which
 | 
					 * - field_attach_form() only takes a single language code, specifying which
 | 
				
			||||||
 *   language the field values will be submitted in.
 | 
					 *   language the field values will be submitted in.
 | 
				
			||||||
 * - field_attach_view() requires the language the entity will be displayed 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
 | 
					 * If the given field has language support enabled, an array of available
 | 
				
			||||||
 * languages will be returned, otherwise only LANGUAGE_NOT_SPECIFIED will be
 | 
					 * language codes will be returned, otherwise only LANGUAGE_NOT_SPECIFIED will
 | 
				
			||||||
 * returned. Since the default value for a 'translatable' entity property is
 | 
					 * be returned. Since the default value for a 'translatable' entity property is
 | 
				
			||||||
 * FALSE, we ensure that only entities that are able to handle translations
 | 
					 * FALSE, we ensure that only entities that are able to handle translations
 | 
				
			||||||
 * actually get translatable fields.
 | 
					 * actually get translatable fields.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
| 
						 | 
					@ -104,38 +104,39 @@ function field_language_delete() {
 | 
				
			||||||
function field_available_languages($entity_type, $field) {
 | 
					function field_available_languages($entity_type, $field) {
 | 
				
			||||||
  static $drupal_static_fast;
 | 
					  static $drupal_static_fast;
 | 
				
			||||||
  if (!isset($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'];
 | 
					  $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
 | 
					    // If the field has language support enabled we retrieve an (alterable) list
 | 
				
			||||||
    // of enabled languages, otherwise we return just LANGUAGE_NOT_SPECIFIED.
 | 
					    // of enabled languages, otherwise we return just LANGUAGE_NOT_SPECIFIED.
 | 
				
			||||||
    if (field_is_translatable($entity_type, $field)) {
 | 
					    if (field_is_translatable($entity_type, $field)) {
 | 
				
			||||||
      $languages = field_content_languages();
 | 
					      $langcodes = field_content_languages();
 | 
				
			||||||
      // Let other modules alter the available languages.
 | 
					      // Let other modules alter the available languages.
 | 
				
			||||||
      $context = array('entity_type' => $entity_type, 'field' => $field);
 | 
					      $context = array('entity_type' => $entity_type, 'field' => $field);
 | 
				
			||||||
      drupal_alter('field_available_languages', $languages, $context);
 | 
					      drupal_alter('field_available_languages', $langcodes, $context);
 | 
				
			||||||
      $field_languages[$entity_type][$field_name] = $languages;
 | 
					      $field_langcodes[$entity_type][$field_name] = $langcodes;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else {
 | 
					    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
 | 
					 * If a non-empty language code suggestion is provided it must appear among the
 | 
				
			||||||
 * available languages, otherwise it will be ignored.
 | 
					 * available language codes, otherwise it will be ignored.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @param $available_languages
 | 
					 * @param $available_langcodes
 | 
				
			||||||
 *   An array of valid language codes.
 | 
					 *   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.
 | 
					 *   A language code or an array of language codes keyed by field name.
 | 
				
			||||||
 * @param $field_name
 | 
					 * @param $field_name
 | 
				
			||||||
 *   The name of the field being processed.
 | 
					 *   The name of the field being processed.
 | 
				
			||||||
| 
						 | 
					@ -143,28 +144,28 @@ function field_available_languages($entity_type, $field) {
 | 
				
			||||||
 * @return
 | 
					 * @return
 | 
				
			||||||
 *   An array of valid language codes.
 | 
					 *   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.
 | 
					  // Handle possible language suggestions.
 | 
				
			||||||
  if (!empty($language_suggestion)) {
 | 
					  if (!empty($langcode_suggestion)) {
 | 
				
			||||||
    // We might have an array of language suggestions keyed by field name.
 | 
					    // We might have an array of language suggestions keyed by field name.
 | 
				
			||||||
    if (is_array($language_suggestion) && isset($language_suggestion[$field_name])) {
 | 
					    if (is_array($langcode_suggestion) && isset($langcode_suggestion[$field_name])) {
 | 
				
			||||||
      $language_suggestion = $language_suggestion[$field_name];
 | 
					      $langcode_suggestion = $langcode_suggestion[$field_name];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // If we have a language suggestion and the suggested language is available,
 | 
					    // If we have a single language code suggestion and it is available, we just
 | 
				
			||||||
    // we return only it.
 | 
					    // return it.
 | 
				
			||||||
    if (in_array($language_suggestion, $available_languages)) {
 | 
					    if (in_array($langcode_suggestion, $available_langcodes)) {
 | 
				
			||||||
      $available_languages = array($language_suggestion);
 | 
					      $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.
 | 
					 * LANGUAGE_NOT_SPECIFIED.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @return
 | 
					 * @return
 | 
				
			||||||
| 
						 | 
					@ -229,9 +230,9 @@ function field_has_translation_handler($entity_type, $handler = NULL) {
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Ensures that a given language code is valid.
 | 
					 * Ensures that a given language code is valid.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Checks whether the given language is one of the enabled languages. Otherwise,
 | 
					 * Checks whether the given language code is one of the enabled language codes.
 | 
				
			||||||
 * it returns the current, global language; or the site's default language, if
 | 
					 * Otherwise, it returns the current, global language code; or the site's
 | 
				
			||||||
 * the additional parameter $default is TRUE.
 | 
					 * default language code, if the additional parameter $default is TRUE.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @param $langcode
 | 
					 * @param $langcode
 | 
				
			||||||
 *   The language code to validate.
 | 
					 *   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
 | 
					 * The actual language code for each given field is determined based on the
 | 
				
			||||||
 * language and the actual data available in the fields themselves.
 | 
					 * 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
 | 
					 * 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
 | 
				
			||||||
 * language code is allowed by field_available_languages().
 | 
					 * language code is allowed by field_available_languages().
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * If translation handlers are found, we let modules provide alternative display
 | 
					 * If translation handlers are found, we let modules provide alternative display
 | 
				
			||||||
 * languages for fields not having the requested language available.
 | 
					 * language codes for fields not having the requested language code available.
 | 
				
			||||||
 * Core language fallback rules are provided by locale_field_language_fallback()
 | 
					 * Core language fallback rules are provided by locale_field_language_fallback()
 | 
				
			||||||
 * which is called by locale_field_language_alter().
 | 
					 * which is called by locale_field_language_alter().
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
| 
						 | 
					@ -270,8 +273,8 @@ function field_valid_language($langcode, $default = TRUE) {
 | 
				
			||||||
 *   The entity to be displayed.
 | 
					 *   The entity to be displayed.
 | 
				
			||||||
 * @param $field_name
 | 
					 * @param $field_name
 | 
				
			||||||
 *   (optional) The name of the field to be displayed. Defaults to NULL. If
 | 
					 *   (optional) The name of the field to be displayed. Defaults to NULL. If
 | 
				
			||||||
 *   no value is specified, the display languages for every field attached to
 | 
					 *   no value is specified, the display language codes for every field attached
 | 
				
			||||||
 *   the given entity will be returned.
 | 
					 *   to the given entity will be returned.
 | 
				
			||||||
 * @param $langcode
 | 
					 * @param $langcode
 | 
				
			||||||
 *   (optional) The language code $entity has to be displayed in. Defaults to
 | 
					 *   (optional) The language code $entity has to be displayed in. Defaults to
 | 
				
			||||||
 *   NULL. If no value is given the current language will be used.
 | 
					 *   NULL. If no value is given the current language will be used.
 | 
				
			||||||
| 
						 | 
					@ -281,38 +284,38 @@ function field_valid_language($langcode, $default = TRUE) {
 | 
				
			||||||
 *   keyed by field name otherwise.
 | 
					 *   keyed by field name otherwise.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function field_language($entity_type, $entity, $field_name = NULL, $langcode = NULL) {
 | 
					function field_language($entity_type, $entity, $field_name = NULL, $langcode = NULL) {
 | 
				
			||||||
  $display_languages = &drupal_static(__FUNCTION__, array());
 | 
					  $display_langcodes = &drupal_static(__FUNCTION__, array());
 | 
				
			||||||
  list($id, , $bundle) = entity_extract_ids($entity_type, $entity);
 | 
					  list($id, , $bundle) = entity_extract_ids($entity_type, $entity);
 | 
				
			||||||
  $langcode = field_valid_language($langcode, FALSE);
 | 
					  $langcode = field_valid_language($langcode, FALSE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!isset($display_languages[$entity_type][$id][$langcode])) {
 | 
					  if (!isset($display_langcodes[$entity_type][$id][$langcode])) {
 | 
				
			||||||
    $display_language = array();
 | 
					    $display_langcode = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // By default display language is set to LANGUAGE_NOT_SPECIFIED if the field
 | 
					    // By default display language is set to LANGUAGE_NOT_SPECIFIED if the field
 | 
				
			||||||
    // translation is not available. It is up to translation handlers to
 | 
					    // translation is not available. It is up to translation handlers to
 | 
				
			||||||
    // implement language fallback rules.
 | 
					    // implement language fallback rules.
 | 
				
			||||||
    foreach (field_info_instances($entity_type, $bundle) as $instance) {
 | 
					    foreach (field_info_instances($entity_type, $bundle) as $instance) {
 | 
				
			||||||
      $display_language[$instance['field_name']] = isset($entity->{$instance['field_name']}[$langcode]) ? $langcode : LANGUAGE_NOT_SPECIFIED;
 | 
					      $display_langcode[$instance['field_name']] = isset($entity->{$instance['field_name']}[$langcode]) ? $langcode : LANGUAGE_NOT_SPECIFIED;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (field_has_translation_handler($entity_type)) {
 | 
					    if (field_has_translation_handler($entity_type)) {
 | 
				
			||||||
      $context = array(
 | 
					      $context = array(
 | 
				
			||||||
        'entity_type' => $entity_type,
 | 
					        'entity_type' => $entity_type,
 | 
				
			||||||
        'entity' => $entity,
 | 
					        'entity' => $entity,
 | 
				
			||||||
        'language' => $langcode,
 | 
					        'langcode' => $langcode,
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
      drupal_alter('field_language', $display_language, $context);
 | 
					      drupal_alter('field_language', $display_langcode, $context);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $display_languages[$entity_type][$id][$langcode] = $display_language;
 | 
					    $display_langcodes[$entity_type][$id][$langcode] = $display_langcode;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  $display_language = $display_languages[$entity_type][$id][$langcode];
 | 
					  $display_langcode = $display_langcodes[$entity_type][$id][$langcode];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Single-field mode.
 | 
					  // Single-field mode.
 | 
				
			||||||
  if (isset($field_name)) {
 | 
					  if (isset($field_name)) {
 | 
				
			||||||
    return isset($display_language[$field_name]) ? $display_language[$field_name] : FALSE;
 | 
					    return isset($display_langcode[$field_name]) ? $display_langcode[$field_name] : FALSE;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return $display_language;
 | 
					  return $display_langcode;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -52,7 +52,7 @@ function _update_7000_field_sql_storage_write($entity_type, $bundle, $entity_id,
 | 
				
			||||||
        'revision_id' => $revision_id,
 | 
					        'revision_id' => $revision_id,
 | 
				
			||||||
        'bundle' => $bundle,
 | 
					        'bundle' => $bundle,
 | 
				
			||||||
        'delta' => $delta,
 | 
					        'delta' => $delta,
 | 
				
			||||||
        'language' => $langcode,
 | 
					        'langcode' => $langcode,
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
      foreach ($item as $column => $value) {
 | 
					      foreach ($item as $column => $value) {
 | 
				
			||||||
        $record[_field_sql_storage_columnname($field_name, $column)] = $value;
 | 
					        $record[_field_sql_storage_columnname($field_name, $column)] = $value;
 | 
				
			||||||
| 
						 | 
					@ -77,3 +77,52 @@ function _update_7000_field_sql_storage_write($entity_type, $bundle, $entity_id,
 | 
				
			||||||
    $revision_query->execute();
 | 
					    $revision_query->execute();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Changes field language into langcode.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function field_sql_storage_update_8000(&$sandbox) {
 | 
				
			||||||
 | 
					  // Prepare updated schema data structures.
 | 
				
			||||||
 | 
					  $primary_key_data = array (
 | 
				
			||||||
 | 
					    'entity_type',
 | 
				
			||||||
 | 
					    'entity_id',
 | 
				
			||||||
 | 
					    'deleted',
 | 
				
			||||||
 | 
					    'delta',
 | 
				
			||||||
 | 
					    'langcode',
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					  $primary_key_revision = array (
 | 
				
			||||||
 | 
					    'entity_type',
 | 
				
			||||||
 | 
					    'entity_id',
 | 
				
			||||||
 | 
					    'revision_id',
 | 
				
			||||||
 | 
					    'deleted',
 | 
				
			||||||
 | 
					    'delta',
 | 
				
			||||||
 | 
					    'langcode',
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					  $langcode_index = array(
 | 
				
			||||||
 | 
					    'langcode',
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					  $field_langcode = array(
 | 
				
			||||||
 | 
					    'type' => 'varchar',
 | 
				
			||||||
 | 
					    'length' => 32,
 | 
				
			||||||
 | 
					    'not null' => true,
 | 
				
			||||||
 | 
					    'default' => '',
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Retrieve field data.
 | 
				
			||||||
 | 
					  $fields = _update_8000_field_read_fields(array('storage_type' => 'field_sql_storage'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Update schema.
 | 
				
			||||||
 | 
					  foreach ($fields as $field) {
 | 
				
			||||||
 | 
					    $data_table = _field_sql_storage_tablename($field);
 | 
				
			||||||
 | 
					    $revision_table = _field_sql_storage_revision_tablename($field);
 | 
				
			||||||
 | 
					    $table_info = array($data_table => $primary_key_data, $revision_table => $primary_key_revision);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    foreach ($table_info as $table => $primary_key) {
 | 
				
			||||||
 | 
					      db_drop_primary_key($table);
 | 
				
			||||||
 | 
					      db_drop_index($table, 'language');
 | 
				
			||||||
 | 
					      db_change_field($table, 'language', 'langcode', $field_langcode);
 | 
				
			||||||
 | 
					      db_add_primary_key($table, $primary_key);
 | 
				
			||||||
 | 
					      db_add_index($table, 'langcode', $langcode_index);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -146,13 +146,13 @@ function _field_sql_storage_schema($field) {
 | 
				
			||||||
        'not null' => FALSE,
 | 
					        'not null' => FALSE,
 | 
				
			||||||
        'description' => 'The entity revision id this data is attached to, or NULL if the entity type is not versioned',
 | 
					        'description' => 'The entity revision id this data is attached to, or NULL if the entity type is not versioned',
 | 
				
			||||||
      ),
 | 
					      ),
 | 
				
			||||||
      // @todo Consider storing language as integer.
 | 
					      // @todo Consider storing langcode as integer.
 | 
				
			||||||
      'language' => array(
 | 
					      'langcode' => array(
 | 
				
			||||||
        'type' => 'varchar',
 | 
					        'type' => 'varchar',
 | 
				
			||||||
        'length' => 32,
 | 
					        'length' => 32,
 | 
				
			||||||
        'not null' => TRUE,
 | 
					        'not null' => TRUE,
 | 
				
			||||||
        'default' => '',
 | 
					        'default' => '',
 | 
				
			||||||
        'description' => 'The language for this data item.',
 | 
					        'description' => 'The language code for this data item.',
 | 
				
			||||||
      ),
 | 
					      ),
 | 
				
			||||||
      'delta' => array(
 | 
					      'delta' => array(
 | 
				
			||||||
        'type' => 'int',
 | 
					        'type' => 'int',
 | 
				
			||||||
| 
						 | 
					@ -161,14 +161,14 @@ function _field_sql_storage_schema($field) {
 | 
				
			||||||
        'description' => 'The sequence number for this data item, used for multi-value fields',
 | 
					        'description' => 'The sequence number for this data item, used for multi-value fields',
 | 
				
			||||||
      ),
 | 
					      ),
 | 
				
			||||||
    ),
 | 
					    ),
 | 
				
			||||||
    'primary key' => array('entity_type', 'entity_id', 'deleted', 'delta', 'language'),
 | 
					    'primary key' => array('entity_type', 'entity_id', 'deleted', 'delta', 'langcode'),
 | 
				
			||||||
    'indexes' => array(
 | 
					    'indexes' => array(
 | 
				
			||||||
      'entity_type' => array('entity_type'),
 | 
					      'entity_type' => array('entity_type'),
 | 
				
			||||||
      'bundle' => array('bundle'),
 | 
					      'bundle' => array('bundle'),
 | 
				
			||||||
      'deleted' => array('deleted'),
 | 
					      'deleted' => array('deleted'),
 | 
				
			||||||
      'entity_id' => array('entity_id'),
 | 
					      'entity_id' => array('entity_id'),
 | 
				
			||||||
      'revision_id' => array('revision_id'),
 | 
					      'revision_id' => array('revision_id'),
 | 
				
			||||||
      'language' => array('language'),
 | 
					      'langcode' => array('langcode'),
 | 
				
			||||||
    ),
 | 
					    ),
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -200,7 +200,7 @@ function _field_sql_storage_schema($field) {
 | 
				
			||||||
  // Construct the revision table.
 | 
					  // Construct the revision table.
 | 
				
			||||||
  $revision = $current;
 | 
					  $revision = $current;
 | 
				
			||||||
  $revision['description'] = "Revision archive storage for {$deleted}field {$field['id']} ({$field['field_name']})";
 | 
					  $revision['description'] = "Revision archive storage for {$deleted}field {$field['id']} ({$field['field_name']})";
 | 
				
			||||||
  $revision['primary key'] = array('entity_type', 'entity_id', 'revision_id', 'deleted', 'delta', 'language');
 | 
					  $revision['primary key'] = array('entity_type', 'entity_id', 'revision_id', 'deleted', 'delta', 'langcode');
 | 
				
			||||||
  $revision['fields']['revision_id']['not null'] = TRUE;
 | 
					  $revision['fields']['revision_id']['not null'] = TRUE;
 | 
				
			||||||
  $revision['fields']['revision_id']['description'] = 'The entity revision id this data is attached to';
 | 
					  $revision['fields']['revision_id']['description'] = 'The entity revision id this data is attached to';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -339,7 +339,7 @@ function field_sql_storage_field_storage_load($entity_type, $entities, $age, $fi
 | 
				
			||||||
      ->fields('t')
 | 
					      ->fields('t')
 | 
				
			||||||
      ->condition('entity_type', $entity_type)
 | 
					      ->condition('entity_type', $entity_type)
 | 
				
			||||||
      ->condition($load_current ? 'entity_id' : 'revision_id', $ids, 'IN')
 | 
					      ->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');
 | 
					      ->orderBy('delta');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (empty($options['deleted'])) {
 | 
					    if (empty($options['deleted'])) {
 | 
				
			||||||
| 
						 | 
					@ -350,11 +350,11 @@ function field_sql_storage_field_storage_load($entity_type, $entities, $age, $fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $delta_count = array();
 | 
					    $delta_count = array();
 | 
				
			||||||
    foreach ($results as $row) {
 | 
					    foreach ($results as $row) {
 | 
				
			||||||
      if (!isset($delta_count[$row->entity_id][$row->language])) {
 | 
					      if (!isset($delta_count[$row->entity_id][$row->langcode])) {
 | 
				
			||||||
        $delta_count[$row->entity_id][$row->language] = 0;
 | 
					        $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();
 | 
					        $item = array();
 | 
				
			||||||
        // For each column declared by the field, populate the item
 | 
					        // For each column declared by the field, populate the item
 | 
				
			||||||
        // from the prefixed database column.
 | 
					        // from the prefixed database column.
 | 
				
			||||||
| 
						 | 
					@ -364,8 +364,8 @@ function field_sql_storage_field_storage_load($entity_type, $entities, $age, $fi
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Add the item to the field values for the entity.
 | 
					        // Add the item to the field values for the entity.
 | 
				
			||||||
        $entities[$row->entity_id]->{$field_name}[$row->language][] = $item;
 | 
					        $entities[$row->entity_id]->{$field_name}[$row->langcode][] = $item;
 | 
				
			||||||
        $delta_count[$row->entity_id][$row->language]++;
 | 
					        $delta_count[$row->entity_id][$row->langcode]++;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -386,39 +386,39 @@ function field_sql_storage_field_storage_write($entity_type, $entity, $op, $fiel
 | 
				
			||||||
    $table_name = _field_sql_storage_tablename($field);
 | 
					    $table_name = _field_sql_storage_tablename($field);
 | 
				
			||||||
    $revision_name = _field_sql_storage_revision_tablename($field);
 | 
					    $revision_name = _field_sql_storage_revision_tablename($field);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $all_languages = field_available_languages($entity_type, $field);
 | 
					    $all_langcodes = field_available_languages($entity_type, $field);
 | 
				
			||||||
    $field_languages = array_intersect($all_languages, array_keys((array) $entity->$field_name));
 | 
					    $field_langcodes = array_intersect($all_langcodes, array_keys((array) $entity->$field_name));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Delete and insert, rather than update, in case a value was added.
 | 
					    // Delete and insert, rather than update, in case a value was added.
 | 
				
			||||||
    if ($op == FIELD_STORAGE_UPDATE) {
 | 
					    if ($op == FIELD_STORAGE_UPDATE) {
 | 
				
			||||||
      // Delete languages present in the incoming $entity->$field_name.
 | 
					      // Delete language codes present in the incoming $entity->$field_name.
 | 
				
			||||||
      // Delete all languages if $entity->$field_name is empty.
 | 
					      // Delete all language codes if $entity->$field_name is empty.
 | 
				
			||||||
      $languages = !empty($entity->$field_name) ? $field_languages : $all_languages;
 | 
					      $langcodes = !empty($entity->$field_name) ? $field_langcodes : $all_langcodes;
 | 
				
			||||||
      if ($languages) {
 | 
					      if ($langcodes) {
 | 
				
			||||||
        db_delete($table_name)
 | 
					        db_delete($table_name)
 | 
				
			||||||
          ->condition('entity_type', $entity_type)
 | 
					          ->condition('entity_type', $entity_type)
 | 
				
			||||||
          ->condition('entity_id', $id)
 | 
					          ->condition('entity_id', $id)
 | 
				
			||||||
          ->condition('language', $languages, 'IN')
 | 
					          ->condition('langcode', $langcodes, 'IN')
 | 
				
			||||||
          ->execute();
 | 
					          ->execute();
 | 
				
			||||||
        db_delete($revision_name)
 | 
					        db_delete($revision_name)
 | 
				
			||||||
          ->condition('entity_type', $entity_type)
 | 
					          ->condition('entity_type', $entity_type)
 | 
				
			||||||
          ->condition('entity_id', $id)
 | 
					          ->condition('entity_id', $id)
 | 
				
			||||||
          ->condition('revision_id', $vid)
 | 
					          ->condition('revision_id', $vid)
 | 
				
			||||||
          ->condition('language', $languages, 'IN')
 | 
					          ->condition('langcode', $langcodes, 'IN')
 | 
				
			||||||
          ->execute();
 | 
					          ->execute();
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Prepare the multi-insert query.
 | 
					    // Prepare the multi-insert query.
 | 
				
			||||||
    $do_insert = FALSE;
 | 
					    $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) {
 | 
					    foreach ($field['columns'] as $column => $attributes) {
 | 
				
			||||||
      $columns[] = _field_sql_storage_columnname($field_name, $column);
 | 
					      $columns[] = _field_sql_storage_columnname($field_name, $column);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    $query = db_insert($table_name)->fields($columns);
 | 
					    $query = db_insert($table_name)->fields($columns);
 | 
				
			||||||
    $revision_query = db_insert($revision_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];
 | 
					      $items = (array) $entity->{$field_name}[$langcode];
 | 
				
			||||||
      $delta_count = 0;
 | 
					      $delta_count = 0;
 | 
				
			||||||
      foreach ($items as $delta => $item) {
 | 
					      foreach ($items as $delta => $item) {
 | 
				
			||||||
| 
						 | 
					@ -430,7 +430,7 @@ function field_sql_storage_field_storage_write($entity_type, $entity, $op, $fiel
 | 
				
			||||||
          'revision_id' => $vid,
 | 
					          'revision_id' => $vid,
 | 
				
			||||||
          'bundle' => $bundle,
 | 
					          'bundle' => $bundle,
 | 
				
			||||||
          'delta' => $delta,
 | 
					          'delta' => $delta,
 | 
				
			||||||
          'language' => $langcode,
 | 
					          'langcode' => $langcode,
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
        foreach ($field['columns'] as $column => $attributes) {
 | 
					        foreach ($field['columns'] as $column => $attributes) {
 | 
				
			||||||
          $record[_field_sql_storage_columnname($field_name, $column)] = isset($item[$column]) ? $item[$column] : NULL;
 | 
					          $record[_field_sql_storage_columnname($field_name, $column)] = isset($item[$column]) ? $item[$column] : NULL;
 | 
				
			||||||
| 
						 | 
					@ -626,8 +626,8 @@ function _field_sql_storage_query_field_conditions(EntityFieldQuery $query, Sele
 | 
				
			||||||
    // Add the specified condition.
 | 
					    // Add the specified condition.
 | 
				
			||||||
    $sql_field = "$table_alias." . $column_callback($field['field_name'], $condition['column']);
 | 
					    $sql_field = "$table_alias." . $column_callback($field['field_name'], $condition['column']);
 | 
				
			||||||
    $query->addCondition($select_query, $sql_field, $condition);
 | 
					    $query->addCondition($select_query, $sql_field, $condition);
 | 
				
			||||||
    // Add delta / language group conditions.
 | 
					    // Add delta / langcode group conditions.
 | 
				
			||||||
    foreach (array('delta', 'language') as $column) {
 | 
					    foreach (array('delta', 'langcode') as $column) {
 | 
				
			||||||
      if (isset($condition[$column . '_group'])) {
 | 
					      if (isset($condition[$column . '_group'])) {
 | 
				
			||||||
        $group_name = $condition[$column . '_group'];
 | 
					        $group_name = $condition[$column . '_group'];
 | 
				
			||||||
        if (!isset($groups[$column][$group_name])) {
 | 
					        if (!isset($groups[$column][$group_name])) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -47,7 +47,7 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase {
 | 
				
			||||||
    $eid = 0;
 | 
					    $eid = 0;
 | 
				
			||||||
    $langcode = LANGUAGE_NOT_SPECIFIED;
 | 
					    $langcode = LANGUAGE_NOT_SPECIFIED;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $columns = array('entity_type', 'entity_id', 'revision_id', 'delta', 'language', $this->field_name . '_value');
 | 
					    $columns = array('entity_type', 'entity_id', 'revision_id', 'delta', 'langcode', $this->field_name . '_value');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Insert data for four revisions to the field revisions table
 | 
					    // Insert data for four revisions to the field revisions table
 | 
				
			||||||
    $query = db_insert($this->revision_table)->fields($columns);
 | 
					    $query = db_insert($this->revision_table)->fields($columns);
 | 
				
			||||||
| 
						 | 
					@ -95,15 +95,16 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase {
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Add a translation in an unavailable language and verify it is not loaded.
 | 
					    // Add a translation in an unavailable language code and verify it is not
 | 
				
			||||||
 | 
					    // loaded.
 | 
				
			||||||
    $eid = $evid = 1;
 | 
					    $eid = $evid = 1;
 | 
				
			||||||
    $unavailable_language = 'xx';
 | 
					    $unavailable_langcode = 'xx';
 | 
				
			||||||
    $entity = field_test_create_stub_entity($eid, $evid, $this->instance['bundle']);
 | 
					    $entity = field_test_create_stub_entity($eid, $evid, $this->instance['bundle']);
 | 
				
			||||||
    $values = array($entity_type, $eid, $evid, 0, $unavailable_language, mt_rand(1, 127));
 | 
					    $values = array($entity_type, $eid, $evid, 0, $unavailable_langcode, mt_rand(1, 127));
 | 
				
			||||||
    db_insert($this->table)->fields($columns)->values($values)->execute();
 | 
					    db_insert($this->table)->fields($columns)->values($values)->execute();
 | 
				
			||||||
    db_insert($this->revision_table)->fields($columns)->values($values)->execute();
 | 
					    db_insert($this->revision_table)->fields($columns)->values($values)->execute();
 | 
				
			||||||
    field_attach_load($entity_type, array($eid => $entity));
 | 
					    field_attach_load($entity_type, array($eid => $entity));
 | 
				
			||||||
    $this->assertFalse(array_key_exists($unavailable_language, $entity->{$this->field_name}), 'Field translation in an unavailable language ignored');
 | 
					    $this->assertFalse(array_key_exists($unavailable_langcode, $entity->{$this->field_name}), 'Field translation in an unavailable language ignored');
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
| 
						 | 
					@ -241,10 +242,10 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase {
 | 
				
			||||||
    $this->assertEqual($count, 0, 'NULL field leaves no data in table');
 | 
					    $this->assertEqual($count, 0, 'NULL field leaves no data in table');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Add a translation in an unavailable language.
 | 
					    // Add a translation in an unavailable language.
 | 
				
			||||||
    $unavailable_language = 'xx';
 | 
					    $unavailable_langcode = 'xx';
 | 
				
			||||||
    db_insert($this->table)
 | 
					    db_insert($this->table)
 | 
				
			||||||
      ->fields(array('entity_type', 'bundle', 'deleted', 'entity_id', 'revision_id', 'delta', 'language'))
 | 
					      ->fields(array('entity_type', 'bundle', 'deleted', 'entity_id', 'revision_id', 'delta', 'langcode'))
 | 
				
			||||||
      ->values(array($entity_type, $this->instance['bundle'], 0, 0, 0, 0, $unavailable_language))
 | 
					      ->values(array($entity_type, $this->instance['bundle'], 0, 0, 0, 0, $unavailable_langcode))
 | 
				
			||||||
      ->execute();
 | 
					      ->execute();
 | 
				
			||||||
    $count = db_select($this->table)
 | 
					    $count = db_select($this->table)
 | 
				
			||||||
      ->countQuery()
 | 
					      ->countQuery()
 | 
				
			||||||
| 
						 | 
					@ -263,7 +264,7 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Update: Field translation is missing but field is not empty. Translation
 | 
					    // Update: Field translation is missing but field is not empty. Translation
 | 
				
			||||||
    // data should survive.
 | 
					    // data should survive.
 | 
				
			||||||
    $entity->{$this->field_name}[$unavailable_language] = array(mt_rand(1, 127));
 | 
					    $entity->{$this->field_name}[$unavailable_langcode] = array(mt_rand(1, 127));
 | 
				
			||||||
    unset($entity->{$this->field_name}[$langcode]);
 | 
					    unset($entity->{$this->field_name}[$langcode]);
 | 
				
			||||||
    field_attach_update($entity_type, $entity);
 | 
					    field_attach_update($entity_type, $entity);
 | 
				
			||||||
    $count = db_select($this->table)
 | 
					    $count = db_select($this->table)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2732,21 +2732,21 @@ class FieldTranslationsTestCase extends FieldTestCase {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Test hook_field_languages() invocation on a translatable field.
 | 
					    // Test hook_field_languages() invocation on a translatable field.
 | 
				
			||||||
    variable_set('field_test_field_available_languages_alter', TRUE);
 | 
					    variable_set('field_test_field_available_languages_alter', TRUE);
 | 
				
			||||||
    $enabled_languages = field_content_languages();
 | 
					    $enabled_langcodes = field_content_languages();
 | 
				
			||||||
    $available_languages = field_available_languages($this->entity_type, $this->field);
 | 
					    $available_langcodes = field_available_languages($this->entity_type, $this->field);
 | 
				
			||||||
    foreach ($available_languages as $delta => $langcode) {
 | 
					    foreach ($available_langcodes as $delta => $langcode) {
 | 
				
			||||||
      if ($langcode != 'xx' && $langcode != 'en') {
 | 
					      if ($langcode != 'xx' && $langcode != 'en') {
 | 
				
			||||||
        $this->assertTrue(in_array($langcode, $enabled_languages), t('%language is an enabled language.', array('%language' => $langcode)));
 | 
					        $this->assertTrue(in_array($langcode, $enabled_langcodes), t('%language is an enabled language.', array('%language' => $langcode)));
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    $this->assertTrue(in_array('xx', $available_languages), t('%language was made available.', array('%language' => 'xx')));
 | 
					    $this->assertTrue(in_array('xx', $available_langcodes), t('%language was made available.', array('%language' => 'xx')));
 | 
				
			||||||
    $this->assertFalse(in_array('en', $available_languages), t('%language was made unavailable.', array('%language' => 'en')));
 | 
					    $this->assertFalse(in_array('en', $available_langcodes), t('%language was made unavailable.', array('%language' => 'en')));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Test field_available_languages() behavior for untranslatable fields.
 | 
					    // Test field_available_languages() behavior for untranslatable fields.
 | 
				
			||||||
    $this->field['translatable'] = FALSE;
 | 
					    $this->field['translatable'] = FALSE;
 | 
				
			||||||
    field_update_field($this->field);
 | 
					    field_update_field($this->field);
 | 
				
			||||||
    $available_languages = field_available_languages($this->entity_type, $this->field);
 | 
					    $available_langcodes = field_available_languages($this->entity_type, $this->field);
 | 
				
			||||||
    $this->assertTrue(count($available_languages) == 1 && $available_languages[0] === LANGUAGE_NOT_SPECIFIED, t('For untranslatable fields only LANGUAGE_NOT_SPECIFIED is available.'));
 | 
					    $this->assertTrue(count($available_langcodes) == 1 && $available_langcodes[0] === LANGUAGE_NOT_SPECIFIED, t('For untranslatable fields only LANGUAGE_NOT_SPECIFIED is available.'));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
| 
						 | 
					@ -2762,14 +2762,14 @@ class FieldTranslationsTestCase extends FieldTestCase {
 | 
				
			||||||
    // Populate some extra languages to check if _field_invoke() correctly uses
 | 
					    // Populate some extra languages to check if _field_invoke() correctly uses
 | 
				
			||||||
    // the result of field_available_languages().
 | 
					    // the result of field_available_languages().
 | 
				
			||||||
    $values = array();
 | 
					    $values = array();
 | 
				
			||||||
    $extra_languages = mt_rand(1, 4);
 | 
					    $extra_langcodes = mt_rand(1, 4);
 | 
				
			||||||
    $languages = $available_languages = field_available_languages($this->entity_type, $this->field);
 | 
					    $langcodes = $available_langcodes = field_available_languages($this->entity_type, $this->field);
 | 
				
			||||||
    for ($i = 0; $i < $extra_languages; ++$i) {
 | 
					    for ($i = 0; $i < $extra_langcodes; ++$i) {
 | 
				
			||||||
      $languages[] = $this->randomName(2);
 | 
					      $langcodes[] = $this->randomName(2);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // For each given language provide some random values.
 | 
					    // For each given language provide some random values.
 | 
				
			||||||
    foreach ($languages as $langcode) {
 | 
					    foreach ($langcodes as $langcode) {
 | 
				
			||||||
      for ($delta = 0; $delta < $this->field['cardinality']; $delta++) {
 | 
					      for ($delta = 0; $delta < $this->field['cardinality']; $delta++) {
 | 
				
			||||||
        $values[$langcode][$delta]['value'] = mt_rand(1, 127);
 | 
					        $values[$langcode][$delta]['value'] = mt_rand(1, 127);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
| 
						 | 
					@ -2784,7 +2784,7 @@ class FieldTranslationsTestCase extends FieldTestCase {
 | 
				
			||||||
      $this->assertEqual($hash, $result, t('The result for %language is correctly stored.', array('%language' => $langcode)));
 | 
					      $this->assertEqual($hash, $result, t('The result for %language is correctly stored.', array('%language' => $langcode)));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $this->assertEqual(count($results), count($available_languages), t('No unavailable language has been processed.'));
 | 
					    $this->assertEqual(count($results), count($available_langcodes), t('No unavailable language has been processed.'));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
| 
						 | 
					@ -2799,23 +2799,23 @@ class FieldTranslationsTestCase extends FieldTestCase {
 | 
				
			||||||
    $entities = array();
 | 
					    $entities = array();
 | 
				
			||||||
    $entity_type = 'test_entity';
 | 
					    $entity_type = 'test_entity';
 | 
				
			||||||
    $entity_count = mt_rand(2, 5);
 | 
					    $entity_count = mt_rand(2, 5);
 | 
				
			||||||
    $available_languages = field_available_languages($this->entity_type, $this->field);
 | 
					    $available_langcodes = field_available_languages($this->entity_type, $this->field);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for ($id = 1; $id <= $entity_count; ++$id) {
 | 
					    for ($id = 1; $id <= $entity_count; ++$id) {
 | 
				
			||||||
      $entity = field_test_create_stub_entity($id, $id, $this->instance['bundle']);
 | 
					      $entity = field_test_create_stub_entity($id, $id, $this->instance['bundle']);
 | 
				
			||||||
      $languages = $available_languages;
 | 
					      $langcodes = $available_langcodes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // Populate some extra languages to check whether _field_invoke()
 | 
					      // Populate some extra languages to check whether _field_invoke()
 | 
				
			||||||
      // correctly uses the result of field_available_languages().
 | 
					      // correctly uses the result of field_available_languages().
 | 
				
			||||||
      $extra_languages = mt_rand(1, 4);
 | 
					      $extra_langcodes = mt_rand(1, 4);
 | 
				
			||||||
      for ($i = 0; $i < $extra_languages; ++$i) {
 | 
					      for ($i = 0; $i < $extra_langcodes; ++$i) {
 | 
				
			||||||
        $languages[] = $this->randomName(2);
 | 
					        $langcodes[] = $this->randomName(2);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // For each given language provide some random values.
 | 
					      // For each given language provide some random values.
 | 
				
			||||||
      $language_count = count($languages);
 | 
					      $language_count = count($langcodes);
 | 
				
			||||||
      for ($i = 0; $i < $language_count; ++$i) {
 | 
					      for ($i = 0; $i < $language_count; ++$i) {
 | 
				
			||||||
        $langcode = $languages[$i];
 | 
					        $langcode = $langcodes[$i];
 | 
				
			||||||
        // Avoid to populate at least one field translation to check that
 | 
					        // Avoid to populate at least one field translation to check that
 | 
				
			||||||
        // per-entity language suggestions work even when available field values
 | 
					        // per-entity language suggestions work even when available field values
 | 
				
			||||||
        // are different for each language.
 | 
					        // are different for each language.
 | 
				
			||||||
| 
						 | 
					@ -2826,8 +2826,8 @@ class FieldTranslationsTestCase extends FieldTestCase {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        // Ensure that a language for which there is no field translation is
 | 
					        // Ensure that a language for which there is no field translation is
 | 
				
			||||||
        // used as display language to prepare per-entity language suggestions.
 | 
					        // used as display language to prepare per-entity language suggestions.
 | 
				
			||||||
        elseif (!isset($display_language)) {
 | 
					        elseif (!isset($display_langcode)) {
 | 
				
			||||||
          $display_language = $langcode;
 | 
					          $display_langcode = $langcode;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2835,7 +2835,7 @@ class FieldTranslationsTestCase extends FieldTestCase {
 | 
				
			||||||
      $entities[$id] = $entity;
 | 
					      $entities[$id] = $entity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // Store per-entity language suggestions.
 | 
					      // Store per-entity language suggestions.
 | 
				
			||||||
      $options['language'][$id] = field_language($entity_type, $entity, NULL, $display_language);
 | 
					      $options['langcode'][$id] = field_language($entity_type, $entity, NULL, $display_langcode);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $grouped_results = _field_invoke_multiple('test_op_multiple', $entity_type, $entities);
 | 
					    $grouped_results = _field_invoke_multiple('test_op_multiple', $entity_type, $entities);
 | 
				
			||||||
| 
						 | 
					@ -2848,14 +2848,14 @@ class FieldTranslationsTestCase extends FieldTestCase {
 | 
				
			||||||
          $this->assertEqual($hash, $result, t('The result for entity %id/%language is correctly stored.', array('%id' => $id, '%language' => $langcode)));
 | 
					          $this->assertEqual($hash, $result, t('The result for entity %id/%language is correctly stored.', array('%id' => $id, '%language' => $langcode)));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      $this->assertEqual(count($results), count($available_languages), t('No unavailable language has been processed for entity %id.', array('%id' => $id)));
 | 
					      $this->assertEqual(count($results), count($available_langcodes), t('No unavailable language has been processed for entity %id.', array('%id' => $id)));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $null = NULL;
 | 
					    $null = NULL;
 | 
				
			||||||
    $grouped_results = _field_invoke_multiple('test_op_multiple', $entity_type, $entities, $null, $null, $options);
 | 
					    $grouped_results = _field_invoke_multiple('test_op_multiple', $entity_type, $entities, $null, $null, $options);
 | 
				
			||||||
    foreach ($grouped_results as $id => $results) {
 | 
					    foreach ($grouped_results as $id => $results) {
 | 
				
			||||||
      foreach ($results as $langcode => $result) {
 | 
					      foreach ($results as $langcode => $result) {
 | 
				
			||||||
        $this->assertTrue(isset($options['language'][$id]), t('The result language %language for entity %id was correctly suggested (display language: %display_language).', array('%id' => $id, '%language' => $langcode, '%display_language' => $display_language)));
 | 
					        $this->assertTrue(isset($options['langcode'][$id]), t('The result language code %langcode for entity %id was correctly suggested (display language: %display_langcode).', array('%id' => $id, '%langcode' => $langcode, '%display_langcode' => $display_langcode)));
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -2875,9 +2875,9 @@ class FieldTranslationsTestCase extends FieldTestCase {
 | 
				
			||||||
    $entity_type = 'test_entity';
 | 
					    $entity_type = 'test_entity';
 | 
				
			||||||
    $entity = field_test_create_stub_entity($eid, $evid, $this->instance['bundle']);
 | 
					    $entity = field_test_create_stub_entity($eid, $evid, $this->instance['bundle']);
 | 
				
			||||||
    $field_translations = array();
 | 
					    $field_translations = array();
 | 
				
			||||||
    $available_languages = field_available_languages($entity_type, $this->field);
 | 
					    $available_langcodes = field_available_languages($entity_type, $this->field);
 | 
				
			||||||
    $this->assertTrue(count($available_languages) > 1, t('Field is translatable.'));
 | 
					    $this->assertTrue(count($available_langcodes) > 1, t('Field is translatable.'));
 | 
				
			||||||
    foreach ($available_languages as $langcode) {
 | 
					    foreach ($available_langcodes as $langcode) {
 | 
				
			||||||
      $field_translations[$langcode] = $this->_generateTestFieldValues($this->field['cardinality']);
 | 
					      $field_translations[$langcode] = $this->_generateTestFieldValues($this->field['cardinality']);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2924,8 +2924,8 @@ class FieldTranslationsTestCase extends FieldTestCase {
 | 
				
			||||||
    $entity = field_test_create_stub_entity(1, 1, $this->instance['bundle']);
 | 
					    $entity = field_test_create_stub_entity(1, 1, $this->instance['bundle']);
 | 
				
			||||||
    $instances = field_info_instances($entity_type, $this->instance['bundle']);
 | 
					    $instances = field_info_instances($entity_type, $this->instance['bundle']);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $enabled_languages = field_content_languages();
 | 
					    $enabled_langcodes = field_content_languages();
 | 
				
			||||||
    $languages = array();
 | 
					    $langcodes = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Generate field translations for languages different from the first
 | 
					    // Generate field translations for languages different from the first
 | 
				
			||||||
    // enabled.
 | 
					    // enabled.
 | 
				
			||||||
| 
						 | 
					@ -2935,48 +2935,48 @@ class FieldTranslationsTestCase extends FieldTestCase {
 | 
				
			||||||
      do {
 | 
					      do {
 | 
				
			||||||
        // Index 0 is reserved for the requested language, this way we ensure
 | 
					        // Index 0 is reserved for the requested language, this way we ensure
 | 
				
			||||||
        // that no field is actually populated with it.
 | 
					        // that no field is actually populated with it.
 | 
				
			||||||
        $langcode = $enabled_languages[mt_rand(1, count($enabled_languages) - 1)];
 | 
					        $langcode = $enabled_langcodes[mt_rand(1, count($enabled_langcodes) - 1)];
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      while (isset($languages[$langcode]));
 | 
					      while (isset($langcodes[$langcode]));
 | 
				
			||||||
      $languages[$langcode] = TRUE;
 | 
					      $langcodes[$langcode] = TRUE;
 | 
				
			||||||
      $entity->{$field_name}[$langcode] = $this->_generateTestFieldValues($field['cardinality']);
 | 
					      $entity->{$field_name}[$langcode] = $this->_generateTestFieldValues($field['cardinality']);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Test multiple-fields display languages for untranslatable entities.
 | 
					    // Test multiple-fields display languages for untranslatable entities.
 | 
				
			||||||
    field_test_entity_info_translatable($entity_type, FALSE);
 | 
					    field_test_entity_info_translatable($entity_type, FALSE);
 | 
				
			||||||
    drupal_static_reset('field_language');
 | 
					    drupal_static_reset('field_language');
 | 
				
			||||||
    $requested_language = $enabled_languages[0];
 | 
					    $requested_langcode = $enabled_langcodes[0];
 | 
				
			||||||
    $display_language = field_language($entity_type, $entity, NULL, $requested_language);
 | 
					    $display_langcodes = field_language($entity_type, $entity, NULL, $requested_langcode);
 | 
				
			||||||
    foreach ($instances as $instance) {
 | 
					    foreach ($instances as $instance) {
 | 
				
			||||||
      $field_name = $instance['field_name'];
 | 
					      $field_name = $instance['field_name'];
 | 
				
			||||||
      $this->assertTrue($display_language[$field_name] == LANGUAGE_NOT_SPECIFIED, t('The display language for field %field_name is %language.', array('%field_name' => $field_name, '%language' => LANGUAGE_NOT_SPECIFIED)));
 | 
					      $this->assertTrue($display_langcodes[$field_name] == LANGUAGE_NOT_SPECIFIED, t('The display language for field %field_name is %language.', array('%field_name' => $field_name, '%language' => LANGUAGE_NOT_SPECIFIED)));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Test multiple-fields display languages for translatable entities.
 | 
					    // Test multiple-fields display languages for translatable entities.
 | 
				
			||||||
    field_test_entity_info_translatable($entity_type, TRUE);
 | 
					    field_test_entity_info_translatable($entity_type, TRUE);
 | 
				
			||||||
    drupal_static_reset('field_language');
 | 
					    drupal_static_reset('field_language');
 | 
				
			||||||
    $display_language = field_language($entity_type, $entity, NULL, $requested_language);
 | 
					    $display_langcodes = field_language($entity_type, $entity, NULL, $requested_langcode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    foreach ($instances as $instance) {
 | 
					    foreach ($instances as $instance) {
 | 
				
			||||||
      $field_name = $instance['field_name'];
 | 
					      $field_name = $instance['field_name'];
 | 
				
			||||||
      $langcode = $display_language[$field_name];
 | 
					      $langcode = $display_langcodes[$field_name];
 | 
				
			||||||
      // As the requested language was not assinged to any field, if the
 | 
					      // As the requested language was not assinged to any field, if the
 | 
				
			||||||
      // returned language is defined for the current field, core fallback rules
 | 
					      // returned language is defined for the current field, core fallback rules
 | 
				
			||||||
      // were successfully applied.
 | 
					      // were successfully applied.
 | 
				
			||||||
      $this->assertTrue(isset($entity->{$field_name}[$langcode]) && $langcode != $requested_language, t('The display language for the field %field_name is %language.', array('%field_name' => $field_name, '%language' => $langcode)));
 | 
					      $this->assertTrue(isset($entity->{$field_name}[$langcode]) && $langcode != $requested_langcode, t('The display language for the field %field_name is %language.', array('%field_name' => $field_name, '%language' => $langcode)));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Test single-field display language.
 | 
					    // Test single-field display language.
 | 
				
			||||||
    drupal_static_reset('field_language');
 | 
					    drupal_static_reset('field_language');
 | 
				
			||||||
    $langcode = field_language($entity_type, $entity, $this->field_name, $requested_language);
 | 
					    $langcode = field_language($entity_type, $entity, $this->field_name, $requested_langcode);
 | 
				
			||||||
    $this->assertTrue(isset($entity->{$this->field_name}[$langcode]) && $langcode != $requested_language, t('The display language for the (single) field %field_name is %language.', array('%field_name' => $field_name, '%language' => $langcode)));
 | 
					    $this->assertTrue(isset($entity->{$this->field_name}[$langcode]) && $langcode != $requested_langcode, t('The display language for the (single) field %field_name is %language.', array('%field_name' => $field_name, '%language' => $langcode)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Test field_language() basic behavior without language fallback.
 | 
					    // Test field_language() basic behavior without language fallback.
 | 
				
			||||||
    variable_set('field_test_language_fallback', FALSE);
 | 
					    variable_set('field_test_language_fallback', FALSE);
 | 
				
			||||||
    $entity->{$this->field_name}[$requested_language] = mt_rand(1, 127);
 | 
					    $entity->{$this->field_name}[$requested_langcode] = mt_rand(1, 127);
 | 
				
			||||||
    drupal_static_reset('field_language');
 | 
					    drupal_static_reset('field_language');
 | 
				
			||||||
    $display_language = field_language($entity_type, $entity, $this->field_name, $requested_language);
 | 
					    $display_langcode = field_language($entity_type, $entity, $this->field_name, $requested_langcode);
 | 
				
			||||||
    $this->assertEqual($display_language, $requested_language, t('Display language behave correctly when language fallback is disabled'));
 | 
					    $this->assertEqual($display_langcode, $requested_langcode, t('Display language behave correctly when language fallback is disabled'));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
| 
						 | 
					@ -2990,13 +2990,13 @@ class FieldTranslationsTestCase extends FieldTestCase {
 | 
				
			||||||
    field_test_entity_info_translatable($this->entity_type, TRUE);
 | 
					    field_test_entity_info_translatable($this->entity_type, TRUE);
 | 
				
			||||||
    $eid = 1;
 | 
					    $eid = 1;
 | 
				
			||||||
    $entity = field_test_create_stub_entity($eid, $eid, $this->instance['bundle']);
 | 
					    $entity = field_test_create_stub_entity($eid, $eid, $this->instance['bundle']);
 | 
				
			||||||
    $available_languages = array_flip(field_available_languages($this->entity_type, $this->field));
 | 
					    $available_langcodes = array_flip(field_available_languages($this->entity_type, $this->field));
 | 
				
			||||||
    unset($available_languages[LANGUAGE_NOT_SPECIFIED]);
 | 
					    unset($available_langcodes[LANGUAGE_NOT_SPECIFIED]);
 | 
				
			||||||
    $field_name = $this->field['field_name'];
 | 
					    $field_name = $this->field['field_name'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Store the field translations.
 | 
					    // Store the field translations.
 | 
				
			||||||
    $entity->is_new = TRUE;
 | 
					    $entity->is_new = TRUE;
 | 
				
			||||||
    foreach ($available_languages as $langcode => $value) {
 | 
					    foreach ($available_langcodes as $langcode => $value) {
 | 
				
			||||||
      $entity->{$field_name}[$langcode][0]['value'] = $value + 1;
 | 
					      $entity->{$field_name}[$langcode][0]['value'] = $value + 1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    field_test_entity_save($entity);
 | 
					    field_test_entity_save($entity);
 | 
				
			||||||
| 
						 | 
					@ -3007,18 +3007,18 @@ class FieldTranslationsTestCase extends FieldTestCase {
 | 
				
			||||||
    $this->drupalPost('test-entity/manage/' . $eid . '/edit', $edit, t('Save'));
 | 
					    $this->drupalPost('test-entity/manage/' . $eid . '/edit', $edit, t('Save'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Check translation revisions.
 | 
					    // Check translation revisions.
 | 
				
			||||||
    $this->checkTranslationRevisions($eid, $eid, $available_languages);
 | 
					    $this->checkTranslationRevisions($eid, $eid, $available_langcodes);
 | 
				
			||||||
    $this->checkTranslationRevisions($eid, $eid + 1, $available_languages);
 | 
					    $this->checkTranslationRevisions($eid, $eid + 1, $available_langcodes);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Check if the field translation attached to the entity revision identified
 | 
					   * Check if the field translation attached to the entity revision identified
 | 
				
			||||||
   * by the passed arguments were correctly stored.
 | 
					   * by the passed arguments were correctly stored.
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  private function checkTranslationRevisions($eid, $evid, $available_languages) {
 | 
					  private function checkTranslationRevisions($eid, $evid, $available_langcodes) {
 | 
				
			||||||
    $field_name = $this->field['field_name'];
 | 
					    $field_name = $this->field['field_name'];
 | 
				
			||||||
    $entity = field_test_entity_test_load($eid, $evid);
 | 
					    $entity = field_test_entity_test_load($eid, $evid);
 | 
				
			||||||
    foreach ($available_languages as $langcode => $value) {
 | 
					    foreach ($available_langcodes as $langcode => $value) {
 | 
				
			||||||
      $passed = isset($entity->{$field_name}[$langcode]) && $entity->{$field_name}[$langcode][0]['value'] == $value + 1;
 | 
					      $passed = isset($entity->{$field_name}[$langcode]) && $entity->{$field_name}[$langcode][0]['value'] == $value + 1;
 | 
				
			||||||
      $this->assertTrue($passed, t('The @language translation for revision @revision was correctly stored', array('@language' => $langcode, '@revision' => $entity->ftvid)));
 | 
					      $this->assertTrue($passed, t('The @language translation for revision @revision was correctly stored', array('@language' => $langcode, '@revision' => $entity->ftvid)));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -101,22 +101,22 @@ function field_test_field_test_op_multiple($entity_type, $entities, $field, $ins
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Implements hook_field_available_languages_alter().
 | 
					 * Implements hook_field_available_languages_alter().
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function field_test_field_available_languages_alter(&$languages, $context) {
 | 
					function field_test_field_available_languages_alter(&$langcodes, $context) {
 | 
				
			||||||
  if (variable_get('field_test_field_available_languages_alter', FALSE)) {
 | 
					  if (variable_get('field_test_field_available_languages_alter', FALSE)) {
 | 
				
			||||||
    // Add an unavailable language.
 | 
					    // Add an unavailable language code.
 | 
				
			||||||
    $languages[] = 'xx';
 | 
					    $langcodes[] = 'xx';
 | 
				
			||||||
    // Remove an available language.
 | 
					    // Remove an available language code.
 | 
				
			||||||
    $index = array_search('en', $languages);
 | 
					    $index = array_search('en', $langcodes);
 | 
				
			||||||
    unset($languages[$index]);
 | 
					    unset($langcodes[$index]);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Implements hook_field_language_alter().
 | 
					 * Implements hook_field_language_alter().
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function field_test_field_language_alter(&$display_language, $context) {
 | 
					function field_test_field_language_alter(&$display_langcode, $context) {
 | 
				
			||||||
  if (variable_get('field_test_language_fallback', TRUE)) {
 | 
					  if (variable_get('field_test_language_fallback', TRUE)) {
 | 
				
			||||||
    locale_field_language_fallback($display_language, $context['entity'], $context['language']);
 | 
					    locale_field_language_fallback($display_langcode, $context['entity'], $context['langcode']);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -94,17 +94,17 @@ function field_test_field_storage_load($entity_type, $entities, $age, $fields, $
 | 
				
			||||||
    foreach ($field_data[$sub_table] as $row) {
 | 
					    foreach ($field_data[$sub_table] as $row) {
 | 
				
			||||||
      if ($row->type == $entity_type && (!$row->deleted || $options['deleted'])) {
 | 
					      if ($row->type == $entity_type && (!$row->deleted || $options['deleted'])) {
 | 
				
			||||||
        if (($load_current && in_array($row->entity_id, $ids)) || (!$load_current && in_array($row->revision_id, $ids))) {
 | 
					        if (($load_current && in_array($row->entity_id, $ids)) || (!$load_current && in_array($row->revision_id, $ids))) {
 | 
				
			||||||
          if (in_array($row->language, field_available_languages($entity_type, $field))) {
 | 
					          if (in_array($row->langcode, field_available_languages($entity_type, $field))) {
 | 
				
			||||||
            if (!isset($delta_count[$row->entity_id][$row->language])) {
 | 
					            if (!isset($delta_count[$row->entity_id][$row->langcode])) {
 | 
				
			||||||
              $delta_count[$row->entity_id][$row->language] = 0;
 | 
					              $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();
 | 
					              $item = array();
 | 
				
			||||||
              foreach ($field['columns'] as $column => $attributes) {
 | 
					              foreach ($field['columns'] as $column => $attributes) {
 | 
				
			||||||
                $item[$column] = $row->{$column};
 | 
					                $item[$column] = $row->{$column};
 | 
				
			||||||
              }
 | 
					              }
 | 
				
			||||||
              $entities[$row->entity_id]->{$field_name}[$row->language][] = $item;
 | 
					              $entities[$row->entity_id]->{$field_name}[$row->langcode][] = $item;
 | 
				
			||||||
              $delta_count[$row->entity_id][$row->language]++;
 | 
					              $delta_count[$row->entity_id][$row->langcode]++;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -126,17 +126,17 @@ function field_test_field_storage_write($entity_type, $entity, $op, $fields) {
 | 
				
			||||||
    $field_name = $field['field_name'];
 | 
					    $field_name = $field['field_name'];
 | 
				
			||||||
    $field_data = &$data[$field_id];
 | 
					    $field_data = &$data[$field_id];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $all_languages = field_available_languages($entity_type, $field);
 | 
					    $all_langcodes = field_available_languages($entity_type, $field);
 | 
				
			||||||
    $field_languages = array_intersect($all_languages, array_keys((array) $entity->$field_name));
 | 
					    $field_langcodes = array_intersect($all_langcodes, array_keys((array) $entity->$field_name));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Delete and insert, rather than update, in case a value was added.
 | 
					    // Delete and insert, rather than update, in case a value was added.
 | 
				
			||||||
    if ($op == FIELD_STORAGE_UPDATE) {
 | 
					    if ($op == FIELD_STORAGE_UPDATE) {
 | 
				
			||||||
      // Delete languages present in the incoming $entity->$field_name.
 | 
					      // Delete languages present in the incoming $entity->$field_name.
 | 
				
			||||||
      // Delete all languages if $entity->$field_name is empty.
 | 
					      // Delete all languages if $entity->$field_name is empty.
 | 
				
			||||||
      $languages = !empty($entity->$field_name) ? $field_languages : $all_languages;
 | 
					      $langcodes = !empty($entity->$field_name) ? $field_langcodes : $all_langcodes;
 | 
				
			||||||
      if ($languages) {
 | 
					      if ($langcodes) {
 | 
				
			||||||
        foreach ($field_data['current'] as $key => $row) {
 | 
					        foreach ($field_data['current'] as $key => $row) {
 | 
				
			||||||
          if ($row->type == $entity_type && $row->entity_id == $id && in_array($row->language, $languages)) {
 | 
					          if ($row->type == $entity_type && $row->entity_id == $id && in_array($row->langcode, $langcodes)) {
 | 
				
			||||||
            unset($field_data['current'][$key]);
 | 
					            unset($field_data['current'][$key]);
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -150,7 +150,7 @@ function field_test_field_storage_write($entity_type, $entity, $op, $fields) {
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    foreach ($field_languages as $langcode) {
 | 
					    foreach ($field_langcodes as $langcode) {
 | 
				
			||||||
      $items = (array) $entity->{$field_name}[$langcode];
 | 
					      $items = (array) $entity->{$field_name}[$langcode];
 | 
				
			||||||
      $delta_count = 0;
 | 
					      $delta_count = 0;
 | 
				
			||||||
      foreach ($items as $delta => $item) {
 | 
					      foreach ($items as $delta => $item) {
 | 
				
			||||||
| 
						 | 
					@ -162,7 +162,7 @@ function field_test_field_storage_write($entity_type, $entity, $op, $fields) {
 | 
				
			||||||
          'bundle' => $bundle,
 | 
					          'bundle' => $bundle,
 | 
				
			||||||
          'delta' => $delta,
 | 
					          'delta' => $delta,
 | 
				
			||||||
          'deleted' => FALSE,
 | 
					          'deleted' => FALSE,
 | 
				
			||||||
          'language' => $langcode,
 | 
					          'langcode' => $langcode,
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
        foreach ($field['columns'] as $column => $attributes) {
 | 
					        foreach ($field['columns'] as $column => $attributes) {
 | 
				
			||||||
          $row->{$column} = isset($item[$column]) ? $item[$column] : NULL;
 | 
					          $row->{$column} = isset($item[$column]) ? $item[$column] : NULL;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -347,11 +347,11 @@ function locale_theme() {
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Implements hook_field_language_alter().
 | 
					 * Implements hook_field_language_alter().
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function locale_field_language_alter(&$display_language, $context) {
 | 
					function locale_field_language_alter(&$display_langcode, $context) {
 | 
				
			||||||
  // Do not apply core language fallback rules if they are disabled or if Locale
 | 
					  // Do not apply core language fallback rules if they are disabled or if Locale
 | 
				
			||||||
  // is not registered as a translation handler.
 | 
					  // is not registered as a translation handler.
 | 
				
			||||||
  if (variable_get('locale_field_language_fallback', TRUE) && field_has_translation_handler($context['entity_type'], 'locale')) {
 | 
					  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']);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -366,32 +366,32 @@ function locale_field_language_alter(&$display_language, $context) {
 | 
				
			||||||
 * behavior can be disabled by setting the 'locale_field_language_fallback'
 | 
					 * behavior can be disabled by setting the 'locale_field_language_fallback'
 | 
				
			||||||
 * variable to FALSE.
 | 
					 * variable to FALSE.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @param $display_language
 | 
					 * @param $field_langcodes
 | 
				
			||||||
 *   A reference to an array of language codes keyed by field name.
 | 
					 *   A reference to an array of language codes keyed by field name.
 | 
				
			||||||
 * @param $entity
 | 
					 * @param $entity
 | 
				
			||||||
 *   The entity to be displayed.
 | 
					 *   The entity to be displayed.
 | 
				
			||||||
 * @param $langcode
 | 
					 * @param $langcode
 | 
				
			||||||
 *   The language code $entity has to be displayed in.
 | 
					 *   The language code $entity has to be displayed in.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
function locale_field_language_fallback(&$display_language, $entity, $langcode) {
 | 
					function locale_field_language_fallback(&$field_langcodes, $entity, $langcode) {
 | 
				
			||||||
  // Lazily init fallback candidates to avoid unnecessary calls.
 | 
					  // Lazily init fallback candidates to avoid unnecessary calls.
 | 
				
			||||||
  $fallback_candidates = NULL;
 | 
					  $fallback_candidates = NULL;
 | 
				
			||||||
  $field_languages = array();
 | 
					  $field_languages = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  foreach ($display_language as $field_name => $field_language) {
 | 
					  foreach ($field_langcodes as $field_name => $field_langcode) {
 | 
				
			||||||
    // If the requested language is defined for the current field use it,
 | 
					    // If the requested language is defined for the current field use it,
 | 
				
			||||||
    // otherwise search for a fallback value among the fallback candidates.
 | 
					    // otherwise search for a fallback value among the fallback candidates.
 | 
				
			||||||
    if (isset($entity->{$field_name}[$langcode])) {
 | 
					    if (isset($entity->{$field_name}[$langcode])) {
 | 
				
			||||||
      $display_language[$field_name] = $langcode;
 | 
					      $field_langcodes[$field_name] = $langcode;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    elseif (!empty($entity->{$field_name})) {
 | 
					    elseif (!empty($entity->{$field_name})) {
 | 
				
			||||||
      if (!isset($fallback_candidates)) {
 | 
					      if (!isset($fallback_candidates)) {
 | 
				
			||||||
        require_once DRUPAL_ROOT . '/core/includes/language.inc';
 | 
					        require_once DRUPAL_ROOT . '/core/includes/language.inc';
 | 
				
			||||||
        $fallback_candidates = language_fallback_get_candidates();
 | 
					        $fallback_candidates = language_fallback_get_candidates();
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      foreach ($fallback_candidates as $fallback_language) {
 | 
					      foreach ($fallback_candidates as $fallback_langcode) {
 | 
				
			||||||
        if (isset($entity->{$field_name}[$fallback_language])) {
 | 
					        if (isset($entity->{$field_name}[$fallback_langcode])) {
 | 
				
			||||||
          $display_language[$field_name] = $fallback_language;
 | 
					          $field_langcodes[$field_name] = $fallback_langcode;
 | 
				
			||||||
          break;
 | 
					          break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue