function locale_field_entity_form_submit in Drupal 7
Handles field language on submit for the given entity type.
Checks if Locale is registered as a translation handler and handle possible language changes.
2 calls to locale_field_entity_form_submit()
- locale_field_comment_form_submit in modules/
locale/ locale.module - Form submit handler for comment_form().
- locale_field_node_form_submit in modules/
locale/ locale.module - Form submit handler for node_form().
File
- modules/
locale/ locale.module, line 429 - Add language handling functionality and enables the translation of the user interface to languages other than English.
Code
function locale_field_entity_form_submit($entity_type, $form, &$form_state) {
if (field_has_translation_handler($entity_type, 'locale')) {
$entity = (object) $form_state['values'];
$current_language = entity_language($entity_type, $entity);
list(, , $bundle) = entity_extract_ids($entity_type, $entity);
foreach (field_info_instances($entity_type, $bundle) as $instance) {
$field_name = $instance['field_name'];
$field = field_info_field($field_name);
$previous_language = $form[$field_name]['#language'];
// Handle a possible language change: new language values are inserted,
// previous ones are deleted.
if ($field['translatable'] && $previous_language != $current_language) {
$form_state['values'][$field_name][$current_language] = $entity->{$field_name}[$previous_language];
$form_state['values'][$field_name][$previous_language] = array();
}
}
}
}