You are here

function entity_translation_form_element_state_replace in Entity Translation 7

Helper function. Sets the right values in $form_state['field'] when using source language values as defaults.

1 call to entity_translation_form_element_state_replace()
entity_translation_prepare_element in ./entity_translation.module
Form element process callback.

File

./entity_translation.module, line 1344

Code

function entity_translation_form_element_state_replace($element, $source_element, $field_name, $source_form_state, &$form_state) {
  if (isset($source_element['#language'])) {
    $source = $source_element['#language'];

    // Iterate through the form structure recursively.
    foreach (element_children($element) as $key) {
      if (isset($source_element[$key])) {
        entity_translation_form_element_state_replace($element[$key], $source_element[$key], $key, $source_form_state, $form_state);
      }
      elseif (isset($source_element[$source])) {
        entity_translation_form_element_state_replace($element[$key], $source_element[$source], $key, $source_form_state, $form_state);
      }
    }
    if (isset($source_element[$source]['#field_parents'])) {
      $source_parents = $source_element[$source]['#field_parents'];
      $langcode = $element['#language'];
      $parents = $element[$langcode]['#field_parents'];
      $source_state = field_form_get_state($source_parents, $field_name, $source, $source_form_state);
      drupal_alter('entity_translation_source_field_state', $source_state);
      field_form_set_state($parents, $field_name, $langcode, $form_state, $source_state);
    }
  }
}