You are here

function _entity_translation_update_field in Entity Translation 7

Stores the given field translations.

1 call to _entity_translation_update_field()
entity_translation_translatable_batch in ./entity_translation.admin.inc
Batch operation. Convert field data to or from LANGUAGE_NONE.

File

./entity_translation.admin.inc, line 741
The entity translation user interface.

Code

function _entity_translation_update_field($entity_type, $entity, $field_name) {
  $empty = 0;
  $field = field_info_field($field_name);

  // Ensure that we are trying to store only valid data.
  foreach ($entity->{$field_name} as $langcode => $items) {
    $entity->{$field_name}[$langcode] = _field_filter_items($field, $entity->{$field_name}[$langcode]);
    $empty += empty($entity->{$field_name}[$langcode]);
  }

  // Save the field value only if there is at least one item available,
  // otherwise any stored empty field value would be deleted. If this happens
  // the range queries would be messed up.
  if ($empty < count($entity->{$field_name})) {
    entity_translation_entity_save($entity_type, $entity);
  }
}