Index: modules/field_ui/field_ui.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/field_ui/field_ui.admin.inc,v retrieving revision 1.4 diff -u -r1.4 field_ui.admin.inc --- modules/field_ui/field_ui.admin.inc 22 Aug 2009 14:34:20 -0000 1.4 +++ modules/field_ui/field_ui.admin.inc 23 Aug 2009 18:49:15 -0000 @@ -95,9 +95,11 @@ ); // Fields. + foreach ($instances as $name => $instance) { $field = field_info_field($instance['field_name']); $admin_field_path = $admin_path . '/fields/' . $instance['field_name']; + $widget_type_options = field_ui_widget_type_options($field['type'], TRUE); $weight = $instance['widget']['weight']; $form[$name] = array( 'label' => array( @@ -109,8 +111,10 @@ 'type' => array( '#markup' => l(t($field_types[$field['type']]['label']), $admin_field_path . '/field-settings', array('attributes' => array('title' => t('Edit field settings.')))), ), - 'widget_type' => array( - '#markup' => l(t($widget_types[$instance['widget']['type']]['label']), $admin_field_path . '/widget-type', array('attributes' => array('title' => t('Change widget type.')))), + 'widget_type' => array( + '#type' => 'select', + '#options' => $widget_type_options, + '#default_value' => $instance['widget']['type'], ), 'edit' => array( '#markup' => l(t('edit'), $admin_field_path, array('attributes' => array('title' => t('Edit instance settings.')))), @@ -536,6 +540,16 @@ } } } + + // change widget type + $field_names = $form['#fields']; + foreach($field_names as $field_name){ + $instance = field_info_instance($field_name,$bundle); + if($instance['widget']['type']!=$form_values[$field_name]['widget_type']){ + $instance['widget']['type']=$form_values[$field_name]['widget_type']; + field_update_instance($instance); + } + } if ($destinations) { $destinations[] = urldecode(substr(drupal_get_destination(), 12)); @@ -831,6 +845,21 @@ $form['field']['module'] = array('#type' => 'value', '#value' => $field['module']); $form['field']['active'] = array('#type' => 'value', '#value' => $field['active']); + // Build the configurable field values. + $description = t('Maximum number of values users can enter for this field.'); + if (field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_DEFAULT) { + $description .= '
' . t("'Unlimited' will provide an 'Add more' button so the users can add as many values as they like."); + } + + $form['field']['cardinality'] = array( + '#type' => 'select', + '#title' => t('Number of values'), + '#options' => array(FIELD_CARDINALITY_UNLIMITED => t('Unlimited')) + drupal_map_assoc(range(1, 10)), + '#default_value' => $field['cardinality'], + '#description' => $description, + ); + + // Add settings provided by the field module. $form['field']['settings'] = array(); $additions = module_invoke($field_type['module'], 'field_settings_form', $field, $instance); @@ -1027,7 +1056,7 @@ $form['instance'] = array( '#tree' => TRUE, '#type' => 'fieldset', - '#title' => t('%type settings', array('%type' => $bundles[$bundle]['label'])), + '#title' => t('%type specific settings', array('%type' => $bundles[$bundle]['label'])), '#description' => t('These settings apply only to the %field field when used in the %type type.', array('%field' => $instance['label'], '%type' => $bundles[$bundle]['label'])), '#pre_render' => array('field_ui_field_edit_instance_pre_render'), ); @@ -1115,42 +1144,7 @@ // will not use it. field_ui_default_value_widget($field, $instance, $form, $form_state); } - - $info = field_info_field_types($field['type']); - $description = '

' . $info['label'] . ': '; - $description .= $info['description'] . '

'; - $form['#prefix'] = '
' . $description . '
'; - - $description = '

' . t('These settings apply to the %field field everywhere it is used.', array('%field' => $instance['label'])) . '

'; - - // Create a form structure for the field values. - $form['field'] = array( - '#type' => 'fieldset', - '#title' => t('%field field settings', array('%field' => $instance['label'])), - '#description' => $description, - '#tree' => TRUE, - ); - - // Build the configurable field values. - $description = t('Maximum number of values users can enter for this field.'); - if (field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_DEFAULT) { - $description .= '
' . t("'Unlimited' will provide an 'Add more' button so the users can add as many values as they like."); - } - $form['field']['cardinality'] = array( - '#type' => 'select', - '#title' => t('Number of values'), - '#options' => array(FIELD_CARDINALITY_UNLIMITED => t('Unlimited')) + drupal_map_assoc(range(1, 10)), - '#default_value' => $field['cardinality'], - '#description' => $description, - ); - - // Add additional field settings from the field module. - $additions = module_invoke($field['module'], 'field_settings_form', $field, $instance); - if (is_array($additions)) { - // @todo Filter additional settings by whether they can be changed. - $form['field']['settings'] = $additions; - } - + $form['submit'] = array('#type' => 'submit', '#value' => t('Save settings')); return $form; } @@ -1277,14 +1271,7 @@ $form_values = $form_state['values']; $instance = $form_values['instance']; - // Update any field settings that have changed. - $field = field_info_field($instance['field_name']); - // Remove the 'bundles' element added by field_info_field. - // @todo This is ugly, there must be a better way. - unset($field['bundles']); - $field = array_merge($field, $form_state['values']['field']); - field_ui_update_field($field); - + // 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']];