From 0025dcbcb1ce4c98f4e1f0e99303d6408646ba61 Mon Sep 17 00:00:00 2001 From: webchick Date: Tue, 28 Feb 2012 11:21:42 -0800 Subject: Issue #684310 by yched, lyricnz, ksenzee, Niklas Fiekas: Fixed When adding existing field 'Label' is cleared when exiting field. --- modules/field_ui/field_ui.admin.inc | 39 +++++++++++++++++++++++-------------- modules/field_ui/field_ui.js | 11 +++++++++-- 2 files changed, 33 insertions(+), 17 deletions(-) (limited to 'modules/field_ui') diff --git a/modules/field_ui/field_ui.admin.inc b/modules/field_ui/field_ui.admin.inc index 1fd1e537a..f19429df5 100644 --- a/modules/field_ui/field_ui.admin.inc +++ b/modules/field_ui/field_ui.admin.inc @@ -540,8 +540,19 @@ function field_ui_field_overview_form($form, &$form_state, $entity_type, $bundle } // Additional row: add existing field. - $existing_field_options = field_ui_existing_field_options($entity_type, $bundle); - if ($existing_field_options && $widget_type_options) { + $existing_fields = field_ui_existing_field_options($entity_type, $bundle); + if ($existing_fields && $widget_type_options) { + // Build list of options. + $existing_field_options = array(); + foreach ($existing_fields as $field_name => $info) { + $text = t('@type: @field (@label)', array( + '@type' => $info['type_label'], + '@label' => $info['label'], + '@field' => $info['field'], + )); + $existing_field_options[$field_name] = truncate_utf8($text, 80, FALSE, TRUE); + } + asort($existing_field_options); $name = '_add_existing_field'; $table[$name] = array( '#attributes' => array('class' => array('draggable', 'tabledrag-leaf', 'add-new')), @@ -617,10 +628,8 @@ function field_ui_field_overview_form($form, &$form_state, $entity_type, $bundle // Add settings for the update selects behavior. $js_fields = array(); - foreach ($existing_field_options as $field_name => $fields) { - $field = field_info_field($field_name); - $instance = field_info_instance($form['#entity_type'], $field_name, $form['#bundle']); - $js_fields[$field_name] = array('label' => $instance['label'], 'type' => $field['type'], 'widget' => $instance['widget']['type']); + foreach ($existing_fields as $field_name => $info) { + $js_fields[$field_name] = array('label' => $info['label'], 'type' => $info['type'], 'widget' => $info['widget_type']); } $form['#attached']['js'][] = array( @@ -1502,7 +1511,7 @@ function field_ui_formatter_options($field_type = NULL) { * Returns an array of existing fields to be added to a bundle. */ function field_ui_existing_field_options($entity_type, $bundle) { - $options = array(); + $info = array(); $field_types = field_info_field_types(); foreach (field_info_instances() as $existing_entity_type => $bundles) { @@ -1521,19 +1530,19 @@ function field_ui_existing_field_options($entity_type, $bundle) { && !field_info_instance($entity_type, $field['field_name'], $bundle) && (empty($field['entity_types']) || in_array($entity_type, $field['entity_types'])) && empty($field_types[$field['type']]['no_ui'])) { - $text = t('@type: @field (@label)', array( - '@type' => $field_types[$field['type']]['label'], - '@label' => t($instance['label']), '@field' => $instance['field_name'], - )); - $options[$instance['field_name']] = (drupal_strlen($text) > 80 ? truncate_utf8($text, 77) . '...' : $text); + $info[$instance['field_name']] = array( + 'type' => $field['type'], + 'type_label' => $field_types[$field['type']]['label'], + 'field' => $field['field_name'], + 'label' => t($instance['label']), + 'widget_type' => $instance['widget']['type'], + ); } } } } } - // Sort the list by field name. - asort($options); - return $options; + return $info; } /** diff --git a/modules/field_ui/field_ui.js b/modules/field_ui/field_ui.js index 0a41c4c6f..3d8881e61 100644 --- a/modules/field_ui/field_ui.js +++ b/modules/field_ui/field_ui.js @@ -45,6 +45,11 @@ Drupal.fieldUIFieldOverview = { $('.field-select', table).each(function () { this.targetSelect = $('.widget-type-select', $(this).parents('tr').eq(0)); this.targetTextfield = $('.label-textfield', $(this).parents('tr').eq(0)); + this.targetTextfield + .data('field_ui_edited', false) + .bind('keyup', function (e) { + $(this).data('field_ui_edited', $(this).val() != ''); + }); $(this).bind('change keyup', function (e, updateText) { var updateText = (typeof updateText == 'undefined' ? true : updateText); @@ -54,8 +59,10 @@ Drupal.fieldUIFieldOverview = { var options = (selectedFieldType && (selectedFieldType in widgetTypes) ? widgetTypes[selectedFieldType] : []); this.targetSelect.fieldUIPopulateOptions(options, selectedFieldWidget); - if (updateText) { - $(this.targetTextfield).attr('value', (selectedField in fields ? fields[selectedField].label : '')); + // Only overwrite the "Label" input if it has not been manually + // changed, or if it is empty. + if (updateText && !this.targetTextfield.data('field_ui_edited')) { + this.targetTextfield.val(selectedField in fields ? fields[selectedField].label : ''); } }); -- cgit v1.2.3