function entity_translation_prepare_element in Entity Translation 7
Form element process callback.
1 string reference to 'entity_translation_prepare_element'
- entity_translation_field_attach_form in ./
entity_translation.module - Implementation of hook_field_attach_form().
File
- ./
entity_translation.module, line 1291
Code
function entity_translation_prepare_element($element, &$form_state) {
static $drupal_static_fast;
if (!isset($drupal_static_fast)) {
$drupal_static_fast =& drupal_static(__FUNCTION__, array(
'source_forms' => array(),
'source_form_states' => array(),
));
}
$source_forms =& $drupal_static_fast['source_forms'];
$source_form_states =& $drupal_static_fast['source_form_states'];
$form = $form_state['complete form'];
$build_id = $form['#build_id'];
$source = $element['#source'];
$entity_type = $element['#entity_type'];
$id = $element['#entity_id'];
// Key the source form cache per entity type and entity id to allow for
// multiple entities on the same entity form.
if (!isset($source_forms[$build_id][$source][$entity_type][$id])) {
$source_form = array(
'#entity_translation_source_form' => TRUE,
'#parents' => $element['#form_parents'],
);
$source_form_state = $form_state;
field_attach_form($entity_type, $element['#entity'], $source_form, $source_form_state, $source);
$source_forms[$build_id][$source][$entity_type][$id] =& $source_form;
$source_form_states[$build_id][$source][$entity_type][$id] =& $source_form_state;
}
$source_form =& $source_forms[$build_id][$source][$entity_type][$id];
$source_form_state = $source_form_states[$build_id][$source][$entity_type][$id];
$langcode = $element['#language'];
$field_name = $element['#field_name'];
// If we are creating a new translation we have to change the form item
// language information from source to target language, this way the user can
// find the form items already populated with the source values while the
// field form element holds the correct language information.
if (isset($source_form[$field_name][$source])) {
$element[$langcode] = $source_form[$field_name][$source];
entity_translation_form_element_language_replace($element, $source, $langcode);
entity_translation_form_element_state_replace($element, $source_form[$field_name], $field_name, $source_form_state, $form_state);
unset($element[$element['#previous']]);
}
return $element;
}