Commit 13784289 authored by webchick's avatar webchick

#557932 by plach and bangpound: Fixed taxonomy term field autocomplete widgets...

#557932 by plach and bangpound: Fixed taxonomy term field autocomplete widgets validation, which broke after translatable fields.
parent 99869767
......@@ -39,7 +39,7 @@ function field_default_form($obj_type, $object, $field, $instance, $langcode, $i
// Populate widgets with default values when creating a new object.
if (empty($items) && empty($id)) {
$items = field_get_default_value($obj_type, $object, $field, $instance);
$items = field_get_default_value($obj_type, $object, $field, $instance, $langcode);
}
$form_element = array();
......
......@@ -1276,9 +1276,10 @@ function field_ui_field_edit_form_validate($form, &$form_state) {
function field_ui_field_edit_form_submit($form, &$form_state) {
$form_values = $form_state['values'];
$instance = $form_values['instance'];
$field_name = $instance['field_name'];
// Update any field settings that have changed.
$field = field_info_field($instance['field_name']);
$field = field_info_field($field_name);
// Remove the 'bundles' element added by field_info_field.
// @todo This is ugly, there must be a better way.
unset($field['bundles']);
......@@ -1287,7 +1288,8 @@ function field_ui_field_edit_form_submit($form, &$form_state) {
// Move the default value from the sample widget to the default value field.
if (isset($instance['default_value_widget'])) {
$instance['default_value'] = $instance['default_value_widget'][$instance['field_name']];
$langcode = $form['instance']['default_value_widget'][$field_name]['#language'];
$instance['default_value'] = $instance['default_value_widget'][$field_name][$langcode];
unset($instance['default_value_widget']);
}
......
......@@ -2172,14 +2172,21 @@ function taxonomy_autocomplete_elements_process($element, &$form_state, $form) {
// See if this element is in the database format or the transformed format,
// and transform it if necessary.
if (is_array($element['#value']) && !array_key_exists($field_key, $element['#value'])) {
$tags = array();
foreach ($element['#default_value'] as $item) {
$tags[$item['value']] = isset($item['taxonomy_term']) ? $item['taxonomy_term'] : taxonomy_term_load($item['value']);
if (is_array($element['#value'])) {
if (!array_key_exists($field_key, $element['#value'])) {
$tags = array();
foreach ($element['#default_value'] as $item) {
$tags[$item['value']] = isset($item['taxonomy_term']) ? $item['taxonomy_term'] : taxonomy_term_load($item['value']);
}
$typed_string = taxonomy_implode_tags($tags);
}
else {
$typed_string = $element['#value'][$field_key];
}
$element['#value'] = taxonomy_implode_tags($tags);
}
$typed_string = $element['#value'];
else {
$typed_string = $element['#value'];
}
$value = array();
$element[$field_key] = array(
......@@ -2211,10 +2218,15 @@ function taxonomy_autocomplete_elements_process($element, &$form_state, $form) {
* FAPI function to validate taxonomy term autocomplete element.
*/
function taxonomy_autocomplete_validate($element, &$form_state) {
$field_name = $element['#field_name'];
if (!isset($form_state['values'][$field_name])) {
return;
}
// Autocomplete widgets do not send their tids in the form, so we must detect
// them here and process them independently.
if ($form_state['values'][$element['#field_name']]['value']) {
$langcode = $form_state['complete form'][$field_name]['#language'];
if ($tags = $form_state['values'][$field_name][$langcode]['value']) {
// @see taxonomy_node_save
$field = $form_state['#fields'][$element['#field_name']]['field'];
$field_key = $element['#columns'][0];
......@@ -2222,7 +2234,7 @@ function taxonomy_autocomplete_validate($element, &$form_state) {
foreach ($field['settings']['allowed_values'] as $tree) {
$vids[] = $tree['vid'];
}
$typed_terms = drupal_explode_tags($form_state['values'][$element['#field_name']]['value']);
$typed_terms = drupal_explode_tags($tags);
$values = array();
foreach ($typed_terms as $typed_term) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment