Index: content.css
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/content.css,v
retrieving revision 1.10
diff -u -r1.10 content.css
--- content.css	27 Nov 2007 15:50:42 -0000	1.10
+++ content.css	26 Dec 2007 11:53:57 -0000
@@ -1,5 +1,6 @@
 /* $Id: content.css,v 1.10 2007/11/27 15:50:42 karens Exp $ */
 
+/* Node display */
 .field .field-label,
 .field .field-label-inline,
 .field .field-label-inline-first {
@@ -30,4 +31,15 @@
   width:auto;
 }
 
+/* 'Manage fields' overview */
+table.content-field-overview, table.content-field-overview fieldset table {
+  width:100%;
+}
+table.content-field-overview td {
+  width:14%;
+}
+.content-field-overview-empty {
+  text-align:center;
+}
+
 
Index: content.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/content.module,v
retrieving revision 1.227
diff -u -r1.227 content.module
--- content.module	26 Dec 2007 11:01:02 -0000	1.227
+++ content.module	26 Dec 2007 18:58:54 -0000
@@ -119,17 +119,6 @@
         'type' => MENU_LOCAL_TASK,
         'weight' => 1,
       );
-      // TODO : temporary (until drag-n-drop does work)
-      $items['admin/content/types/'. $type_url_str .'/fields_dnd'] = array(
-        'title' => 'Manage fields (d-n-d)',
-        'page callback' => 'drupal_get_form',
-        'page arguments' => array('content_admin_field_overview_dnd_form', $type_name),
-        'access arguments' => array('administer content types'),
-        'file' => 'content_admin.inc',
-        'file path' => drupal_get_path('module', 'content'),
-        'type' => MENU_LOCAL_TASK,
-        'weight' => 1,
-      );
       $items['admin/content/types/'. $type_url_str .'/display'] = array(
         'title' => 'Display fields',
         'page callback' => 'drupal_get_form',
@@ -188,9 +177,6 @@
     'content_admin_field_overview_form' => array(
       'arguments' => array('form' => NULL),
     ),
-    'content_admin_field_overview_dnd_form' => array(
-      'arguments' => array('form' => NULL),
-    ),
     'content_admin_display_overview_form' => array(
       'arguments' => array('form' => NULL),
     ),
@@ -586,8 +572,20 @@
  * Generate field render arrays.
  */
 function content_view(&$node, $teaser = FALSE, $page = FALSE) {
+  // Merge fields.
   $additions = _content_field_invoke_default('view', $node);
   $node->content = array_merge((array) $node->content, $additions);
+  // Adjust weights for non-cck fields.
+  foreach (_content_extra_fields($node->type) as $key => $value) {
+    // Some core 'fields' use a different key in node forms and in 'view'
+    // render arrays.
+    if (isset($value['view']) && isset($node->content[$value['view']])) {
+      $node->content[$value['view']]['#weight'] = $value['weight'];
+    }
+    elseif (isset($node->content[$key])) {
+      $node->content[$key]['#weight'] = $value['weight'];
+    }
+  }
 }
 
 /**
@@ -647,9 +645,14 @@
  *  Implementation of hook_form_alter().
  */
 function content_form_alter(&$form, $form_state, $form_id) {
-  if (isset($form['type'])) {
-    if ($form['type']['#value'] .'_node_form' == $form_id) {
-      $form = array_merge($form, content_form($form, $form_state));
+  if (isset($form['type']) && ($form['type']['#value'] .'_node_form' == $form_id)) {
+    // Merge field widgets.
+    $form = array_merge($form, content_form($form, $form_state));
+    // Adjust weights for non-cck fields.
+    foreach (_content_extra_fields($form['type']['#value']) as $key => $value) {
+      if (isset($form[$key])) {
+        $form[$key]['#weight'] = $value['weight'];
+      }
     }
   }
 }
@@ -1744,4 +1747,80 @@
     //dsm($op);
     //dsm($field);
   }
-}
\ No newline at end of file
+}
+
+/**
+ * Implementation of hook_content_extra_fields.
+ *
+ * Informations for non-CCK 'node fields' defined in core.
+ */
+function content_content_extra_fields($type_name) {
+  $type = content_types($type_name);
+  $extra = array();
+
+  if ($type['has_title']) {
+    $extra['title'] = array('label' => $type['title_label'], 'weight' => -5);
+  }
+  if ($type['has_body']) {
+    $extra['body_field'] = array('label' => $type['body_label'], 'weight' => 0, 'view' => 'body');
+  }
+  if (module_exists('locale') && variable_get("language_$type_name", 0)) {
+    $extra['language'] = array('label' => t('Language'), 'weight' => 0);
+  }
+  if (module_exists('menu')) {
+    $extra['menu'] = array('label' => t('Menu settings'), 'weight' => -2);
+  }
+  if (module_exists('taxonomy') && taxonomy_get_vocabularies($type_name)) {
+    $extra['taxonomy'] = array('label' => t('Taxonomy'), 'weight' => -3);
+  }
+  if (module_exists('upload') && variable_get("upload_$type_name", TRUE)) {
+    $extra['attachments'] = array('label' => t('File attachments'), 'weight' => 30, 'view' => 'files');
+  }
+
+  return $extra;
+}
+
+/**
+ * Retrieve information about non-CCK node 'fields'.
+ */
+function _content_extra_fields($type_name) {
+  static $extra = array();
+
+  if (empty($extra[$type_name])) {
+    $extra[$type_name] = module_invoke_all('content_extra_fields', $type_name);
+    // Add saved weights.
+    foreach (variable_get('content_extra_weights_'. $type_name, array()) as $key => $value) {
+      // Some stored entries might not exist anymore, for instance if uploads
+      // have been disabled, or vocabularies removed...
+      if (isset($extra[$type_name][$key])) {
+        $extra[$type_name][$key]['weight'] = $value;
+      }
+    }
+  }
+
+  return $extra[$type_name];
+}
+
+/**
+ * Retrieve the user-defined weight for non-CCK node 'fields'.
+ *
+ * CCK's 'Manage fields' page lets users reorder node fields, including non-CCK
+ * items (body, taxonomy, other hook_nodeapi-added elements by contrib modules...).
+ * Contrib modules that want to have their 'fields' supported need to expose
+ * them with hook_content_extra_fields, and use this function to retrieve the
+ * user-defined weight.
+ *
+ * @param $type_name
+ *   The content type name.
+ * @param $pseudo_field_name
+ *   The name of the 'field'.
+ * @return
+ *   The weight for the 'field', respecting the user settings stored
+ *   by content.module.
+ */
+function content_extra_field_weight($type_name, $pseudo_field_name) {
+  $extra = _content_extra_fields($type_name);
+  if (isset($extra[$pseudo_field_name])) {
+    return $extra[$pseudo_field_name]['weight'];
+  }
+}
Index: content_admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/content_admin.inc,v
retrieving revision 1.131
diff -u -r1.131 content_admin.inc
--- content_admin.inc	16 Dec 2007 04:22:09 -0000	1.131
+++ content_admin.inc	26 Dec 2007 19:01:16 -0000
@@ -39,407 +39,137 @@
 }
 
 /**
- * Menu callback; presents a listing of fields for a content type.
+ * Menu callback; listing of fields for a content type.
  *
- * Form includes form widgets to set weight and group for each item
- * and displays other form elements and their weights to make it
- * easier to place CCK fields in the form and see where they will appear.
+ * Allows fields to be reordered and nested in fieldgroups using
+ * JS drag-n-drop. Non-CCK form elements can also be moved around.
  */
 function content_admin_field_overview_form(&$form_state, $type_name) {
-  module_load_include('inc', 'node', 'node.pages');
-  $form = array();
-
   $type = content_types($type_name);
-  $field_types = _content_field_types();
 
-  // Create a dummy node and form and call hook_form_alter()
-  // to produce an array of fields and weights added to the node by all modules.
-  $dummy_node = new stdClass();
-  $dummy_node->type = $type['type'];
-  $dummy_node->name = '';
-
-  // Some modules (userreview...) "hide" their node forms, resulting in no field
-  // being listed. We set a special flag to inform them this form is special.
-  $dummy_node->cck_dummy_node_form = TRUE;
-
-  $form_state = array();
-  $dummy_form = array();
-  $dummy_form = node_form($form_state, $dummy_node);
-  foreach (module_implements('form_alter') as $module) {
-    $function = $module .'_form_alter';
-    $function($dummy_form, $form_state, $dummy_node->type .'_node_form');
-  }
-
-  // Move group fields into a 'fields' subgroup to make them easier to identify.
-  // Remove fields that are used in groups from the form, the group will handle them.
+  // CCK fields and groups.
+  $fields = $type['fields'];
+  $groups = $group_options = array();
   if (module_exists('fieldgroup')) {
-    $form['#groups']       = fieldgroup_groups($type['type']);
-    $form['#group_labels'] = _fieldgroup_groups_label($type['type']);
-    if (!$form['#groups']) {
-      drupal_set_message(t('There are no groups configured for this content type.'));
-    }
-    foreach ($form['#groups'] as $group) {
-      foreach ($group['fields'] as $field_name => $field) {
-        unset($dummy_form[$field_name]);
-      }
-    }
+    $groups = fieldgroup_groups($type['type']);
+    $group_options = _fieldgroup_groups_label($type['type']);
   }
 
-  if (!$type['fields']) {
-    drupal_set_message(t('There are no fields configured for this content type.'));
-  }
+  // Non-CCK 'fields'.
+  $extra = _content_extra_fields($type_name);
 
-  if (empty($type['fields']) && empty($form['#groups'])) {
-    return $form;
+  // Rows in this table are essentially nested, but for the simplicity of
+  // theme and submit functions, we keep them in a flat array, and use a
+  // $dummy render structure to figure the right display order for the rows.
+  $dummy = array();
+
+  $form = array(
+    '#tree' => TRUE,
+    '#type_name' => $type['type'],
+    '#fields' => array_keys($fields),
+    '#groups' => array_keys($groups),
+    '#extra' => array_keys($extra),
+    '#order' => array(),
+  );
+
+  // Fields.
+  foreach ($fields as $name => $field) {
+    $weight = $field['widget']['weight'];
+    $form[$name] = array(
+      'label' => array('#value' => $field['widget']['label']),
+      'name' => array('#value' => $field['field_name']),
+      'type' => array('#value' => $field['type']),
+      'configure' => array('#value' => l(t('configure'), 'admin/content/types/'. $type['url_str'] .'/fields/'. $field['field_name'] .'/edit')),
+      'remove' => array('#value' => l(t('remove'), 'admin/content/types/'. $type['url_str'] .'/fields/'. $field['field_name'] .'/remove')),
+      'weight' => array('#type' => 'textfield', '#default_value' => $weight),
+      'parent' => array('#type' => 'select', '#options' => $group_options, '#default_value' => ''),
+      'hidden_name' => array('#type' => 'hidden', '#default_value' => $field['field_name']),
+      '#leaf' => TRUE,
+    );
+    $dummy[$name] = array('#weight' => $weight, '#value' => $name .' ');
   }
-
-  $form['disabled']['#value'] = array();
-
-  // Iterate through the dummy form and add top-level fields and weights to a table.
-  // Construct the table values in an array '#table' that FAPI will ignore, keyed on the item's weight.
-  // Create separate form elements for each weight and group value and put a placeholder for each in #table.
-  $field_names = array_keys(content_fields());
-  foreach ($dummy_form as $key => $value) {
-    // Limiting weight to < 10 will keep workflow and submit elements from being added to the overview table.
-    // They're outside the weight range allowed for CCK fields, so won't interfere with field placement.
-    // Currently the 'menu' fieldset is at weight -2, so add a special check for that one.
-    if (is_array($value) && (isset($value['#weight']) || $key == 'body_filter') && $key != 'menu' && $value['#weight'] <= 10) {
-
-      // if this item is a group, insert group info into table, then add all the group fields below it
-      if (substr($key, 0, 6) == 'group_' && isset($form['#groups'])) {
-        $row = $group_form = array();
-        $row['label']     = $form['#group_labels'][$form['#groups'][$key]['group_name']];
-        $row['name']      = $form['#groups'][$key]['group_name'];
-        $row['type']      = t('group');
-        $row['weights']   = 'form-group-weights';
-        $row['groups']    = '';
-        $row['configure'] = l(t('configure'), 'admin/content/types/'. $type['url_str'] .'/groups/'. $form['#groups'][$key]['group_name'] .'/edit');
-        $row['remove']    = l(t('remove'), 'admin/content/types/'. $type['url_str'] .'/groups/'. $form['#groups'][$key]['group_name'] .'/remove');
-        $data = $row;
-
-        $form['group-weights'][$key] = array('#type' => 'weight', '#default_value' => $value['#weight']);
-        foreach ($form['#groups'][$key]['fields'] as $field_name => $field) {
-          $row = array();
-          $field = $type['fields'][$field_name];
-          $row['label']     = $field['widget']['label'];
-          $row['name']      = $field['field_name'];
-          $row['type']      = $field_types[$field['type']]['label'];
-          $row['weights']   = 'form-field-weights';
-          $row['groups']    = 'form-field-groups';
-          $row['configure'] = l(t('configure'), 'admin/content/types/'. $type['url_str'] .'/fields/'. $field_name);
-          $row['remove']    = l(t('remove'), 'admin/content/types/'. $type['url_str'] .'/fields/'. $field_name .'/remove');
-          $group_form[$field['widget']['weight']][] = array($field_name => $row);
-
-          $form['field-weights'][$field_name] = array('#type' => 'weight', '#default_value' => $field['widget']['weight']);
-          $form['field-groups'][$field_name]  = array('#type' => 'select', '#options' => $form['#group_labels'], '#default_value' => fieldgroup_get_group($type['type'], $field_name));
-          $form['field-groups-defaults'][$field_name]  = array('#type' => 'hidden', '#default_value' => fieldgroup_get_group($type['type'], $field_name));
-        }
-        // sort the group fields by weight
-        ksort($group_form);
-        $group = (array) $data + array('fields' => $group_form);
-        $form['#table'][$value['#weight']][] = array($key => $group);
-      }
-
-      // else if this item is a top-level field, insert field row into the table
-      elseif (in_array($key, $field_names)) {
-        $row = array();
-        $field = $type['fields'][$key];
-        $row['label']     = $field['widget']['label'];
-        $row['name']      = $field['field_name'];
-        $row['type']      = $field_types[$field['type']]['label'];
-        $row['weights']   = 'form-field-weights';
-        if (isset($form['#groups'])) {
-          $row['groups']  = 'form-field-groups';
-        }
-        $row['configure'] = l(t('configure'), 'admin/content/types/'. $type['url_str'] .'/fields/'. $key);
-        $row['remove']    = l(t('remove'), 'admin/content/types/'. $type['url_str'] .'/fields/'. $key .'/remove');
-        $form['#table'][$field['widget']['weight']][] = array($key => $row);
-
-        $form['field-weights'][$key] = array('#type' => 'weight', '#default_value' => $field['widget']['weight']);
-        if (isset($form['#groups'])) {
-          $form['field-groups'][$key]  = array('#type' => 'select', '#options' => $form['#group_labels'], '#default_value' => fieldgroup_get_group($type['type'], $key));
-        }
-      }
-
-      // otherwise this is some other form field or fieldset
-      // if it has a weight display it as a disabled item
-      else {
-        $row = array();
-        $row['label']     = $key == 'body_filter' ? t('body') : $key;
-        $row['name']      = $key;
-        $row['type']      = $key;
-        $row['weights']   = 'form-field-weights';
-        if (isset($form['#groups'])) {
-          $row['groups']  = '';
-        }
-        $row['configure'] = '';
-        $row['remove']    = '';
-        $form['#table'][$value['#weight']][] = array($key => $row);
-        $form['disabled']['#value'][] = $key;
-
-        $form['field-weights'][$key] = array('#type' => 'weight', '#default_value' => $value['#weight'], '#disabled' => TRUE);
-      }
-    }
+  // Groups.
+  foreach ($groups as $name => $group) {
+    $weight = $group['weight'];
+    $form[$name] = array(
+      'label' => array('#value' => $group['label']),
+      'name' => array('#value' => $group['group_name']),
+      'type' => array(),
+      'configure' => array('#value' => l(t('configure'), 'admin/content/types/'. $type['url_str'] .'/groups/'. $group['group_name'] .'/edit')),
+      'remove' => array('#value' => l(t('remove'), 'admin/content/types/'. $type['url_str'] .'/groups/'. $group['group_name'] .'/remove')),
+      'weight' => array('#type' => 'textfield', '#default_value' => $weight),
+      'parent' => array('#type' => 'hidden', '#default_value' => ''),
+      'hidden_name' => array('#type' => 'hidden', '#default_value' => $group['group_name']),
+      '#root' => TRUE,
+    );
+    $dummy[$name] = array('#weight' => $weight, '#value' => $name .' ');
+    // Adjust child fields rows.
+    foreach ($group['fields'] as $field_name => $field) {
+      $form[$field_name]['#depth'] = 1;
+      $form[$field_name]['parent']['#default_value'] = $name;
+      $dummy[$name][$field_name] = $dummy[$field_name];
+      unset($dummy[$field_name]);
+    }
+  }
+  // Non-CCK 'fields'.
+  foreach ($extra as $name => $label) {
+    $weight = $extra[$name]['weight'];
+    $form[$name] = array(
+      'label' => array('#value' => $extra[$name]['label']),
+      'name' => array(),
+      'type' => array(),
+      'configure' => array(),
+      'remove' => array(),
+      'weight' => array('#type' => 'textfield', '#default_value' => $weight),
+      'parent' => array('#type' => 'hidden', '#default_value' => ''),
+      'hidden_name' => array('#type' => 'hidden', '#default_value' => $name),
+      '#leaf' => TRUE,
+      '#root' => TRUE,
+      '#disabled' => TRUE,
+    );
+    $dummy[$name] = array('#weight' => $weight, '#value' => $name .' ');
   }
 
-  // sort the table by weight
-  ksort($form['#table']);
-
-  // add submit buttons and hidden fields
-  $form['submit']                         = array('#type' => 'submit', '#value' => t('Update'));
-  $form['field-weights']['#tree']         = TRUE;
-  $form['group-weights']['#tree']         = TRUE;
-  $form['field-groups']['#tree']          = TRUE;
-  $form['field-groups-defaults']['#tree'] = TRUE;
-  $form['disabled']['#type']              = 'hidden';
-  $form['disabled']['#value']             = serialize($form['disabled']['#value']);
-  $form['type_name']['#type']             = 'hidden';
-  $form['type_name']['#value']            = $type['type'];
+  // Let drupal_render figure out the right order for the rows.
+  $form['#order'] = explode(' ', trim(drupal_render($dummy)));
 
+  $form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
   return $form;
 }
 
 /**
- *  Theme the field overview table by iterating through the form and rendering form elements in table cells
+ *  Theme the field overview table.
  */
 function theme_content_admin_field_overview_form($form) {
-  if (empty($form['#table'])) {
-    return;
-  }
-
-  // The css for this form contains non-validating styles,
-  // so we use a separate file, included only on the relevant page.
-  drupal_add_css(drupal_get_path('module', 'content') .'/content_admin.css');
-
-  $disabled = unserialize($form['disabled']['#value']);
-
-  if (module_exists('fieldgroup')) {
-    $header = array(t('Label'), t('Name'), t('Type'), t('Weight'), t('Group'), array('data' => t('Operations'), 'colspan' => 2));
-    $colspan = 7;
-  }
-  else {
-    $header = array(t('Label'), t('Name'), t('Type'), t('Weight'), array('data' => t('Operations'), 'colspan' => 2));
-    $colspan = 6;
-  }
-
-  $rows = array();
-  $i = 0;
-
-  // The table was created in the form
-  // iterate through it and render form elements when placeholders are encountered
-  // then run the rows array through theme_table().
-  foreach ($form['#table'] as $weight => $frow) {
-    foreach ($frow as $delta => $item) {
-      foreach ($item as $fname => $field) {
-        $row = array();
-        $class = 'content-field-overview-enabled';
-        if (in_array($fname, $disabled)) {
-          $class = 'content-field-overview-disabled';
-        }
-        foreach ($field as $col => $cell) {
-          // display cols other than the group 'fields' col
-          if ($col != 'fields') {
-            switch ($cell) {
-            case 'form-field-weights':
-              $row[] = drupal_render($form['field-weights'][$fname]);
-              break;
-            case 'form-group-weights':
-              $row[] = drupal_render($form['group-weights'][$fname]);
-              break;
-            case 'form-field-groups':
-              $row[] = drupal_render($form['field-groups'][$fname]);
-              break;
-            default:
-              $row[] = array('data' => $cell, 'class' => $class);
-            }
-          }
-
-          elseif (isset($form['#groups'])) {
-            // if this form contains groups info and this is a group 'fields' col, finish the previous row
-            // then theme the 'fields' col with a fieldset containing a table and the group fields
-            $grows = array();
-
-            if (!empty($cell)) {
-              foreach ($cell as $gweight => $grow) {
-                foreach ($grow as $gdelta => $gitem) {
-                  foreach ($gitem as $gname => $gfield) {
-                    $grow = array();
-                    foreach ($gfield as $gcol => $gcell) {
-                      switch ($gcell) {
-                        case 'form-field-weights':
-                          $grow[] = drupal_render($form['field-weights'][$gname]);
-                          break;
-                        case 'form-field-groups':
-                          $grow[] = drupal_render($form['field-groups'][$gname]);
-                          break;
-                        default:
-                          $grow[] = $gcell;
-                      }
-                    }
-                    $grows[] = array('data' => $grow, 'class' => 'content-field-overview-enabled');
-                  }
-                }
-              }
-            }
-            else {
-              $grows[] = array(array('data' => t('No fields have been added to this group.'), 'colspan' => $colspan, 'class' => 'content-field-overview-empty'));
-            }
-
-            // add the group row in its own table above the group fields table, then reset $row().
-            $fieldset = array(
-              '#title' => t('!label (!name)', array('!label' => $form['#group_labels'][$fname], '!name' => $fname)),
-              '#collapsible' => TRUE,
-              '#collapsed' => FALSE,
-              '#value' => theme('table', array(), array(array('data' => $row, 'class' => 'content-field-overview-group'))) . theme('table', $header, $grows),
-              );
-            $row = array();
-            $row[] = array(
-              'data' => theme('fieldset', $fieldset),
-              'colspan' => $colspan,
-              'class' => 'active',
-              );
-            $grows = array();
-          }
-        }
-        $rows[] = $row;
-      }
-    }
-  }
-  $output  = theme('table', $header, $rows, array('class' => 'content-field-overview'));
-  $output .= drupal_render($form);
-  return $output;
-
-}
-
-function content_admin_field_overview_dnd_form(&$form_state, $type_name) {
-  module_load_include('inc', 'node', 'node.pages');
-
-  $type = content_types($type_name);
-  $field_types = _content_field_types();
-
-  // Create a dummy node and form and call hook_form_alter()
-  // to produce an array of fields and weights added to the node by all modules.
-  $dummy_node = new stdClass();
-  $dummy_node->type = $type['type'];
-  $dummy_node->name = '';
-
-  // Some modules (userreview...) "hide" their node forms, resulting in no field
-  // being listed. We set a special flag to inform them this form is special.
-  $dummy_node->cck_dummy_node_form = TRUE;
-
-  $form_state = array();
-  $dummy_form = array();
-  $dummy_form = node_form($form_state, $dummy_node);
-  foreach (module_implements('form_alter') as $module) {
-    $function = $module .'_form_alter';
-    $function($dummy_form, $form_state, $dummy_node->type .'_node_form');
-  }
-
-  $form = array();
-  $form['#type_name'] = $type['type'];
-  $groups = module_exists('fieldgroup') ? fieldgroup_groups($type['type']) : array();
-  $group_options = _fieldgroup_groups_label($type['type']);
-
-  if (empty($type['fields'])) {
-    drupal_set_message(t('There are no fields configured for this content type.'));
-  }
-  if (empty($groups)) { // TODO : if fieldgroups disabled
-    drupal_set_message(t('There are no groups configured for this content type.'));
-  }
-
-  foreach ($dummy_form as $key => $value) {
-    if (is_array($value) && (isset($value['#weight']) || $key == 'body_filter') && $key != 'menu' && $value['#weight'] <= 10) {
-      if (isset($groups[$key])) {
-        $group = $groups[$key];
-        $form[$key]['label']['#value'] = $group['label'];
-        $form[$key]['name']['#value'] = $group['group_name'];
-        $form[$key]['type']['#value'] = t('group');
-        $form[$key]['configure']['#value'] = l(t('configure'), 'admin/content/types/'. $type['url_str'] .'/groups/'. $group['group_name'] .'/edit');
-        $form[$key]['remove']['#value'] = l(t('remove'), 'admin/content/types/'. $type['url_str'] .'/groups/'. $group['group_name'] .'/remove');
-        $form[$key]['weight'] = array('#type' => 'weight', '#default_value' => $group['weight']);
-        $form[$key]['parent'] = array('#type' => 'textfield', '#default_value' => '');
-        $form[$key]['hidden_name'] = array('#type' => 'hidden', '#default_value' => $group['group_name']);
-        $form[$key]['#root'] = TRUE;
-        // Add child fields...
-        foreach ($group['fields'] as $field_name => $field) {
-          $field = $type['fields'][$field_name];
-          $form[$field_name]['label']['#value'] = $field['widget']['label'];
-          $form[$field_name]['name']['#value'] = $field['field_name'];
-          $form[$field_name]['type']['#value'] = $field['type'];
-          $form[$field_name]['configure']['#value'] = l(t('configure'), 'admin/content/types/'. $type['url_str'] .'/fields/'. $field['field_name'] .'/edit');
-          $form[$field_name]['remove']['#value'] = l(t('remove'), 'admin/content/types/'. $type['url_str'] .'/fields/'. $field['field_name'] .'/remove');
-          $form[$field_name]['weight'] = array('#type' => 'weight', '#default_value' => $field['widget']['weight']);
-          $form[$field_name]['parent'] = array('#type' => 'select', '#options' => $group_options, '#default_value' => $group['group_name']);
-          $form[$field_name]['hidden_name'] = array('#type' => 'hidden', '#default_value' => $field['field_name']);
-          $form[$field_name]['#depth'] = 1;
-          $form[$field_name]['#leaf'] = TRUE;
-        }
-      }
-      elseif (isset($type['fields'][$key])) {
-        $field = $type['fields'][$key];
-        $form[$key]['label']['#value'] = $field['widget']['label'];
-        $form[$key]['name']['#value'] = $field['field_name'];
-        $form[$key]['type']['#value'] = $field['type'];
-        $form[$key]['configure']['#value'] = l(t('configure'), 'admin/content/types/'. $type['url_str'] .'/fields/'. $field['field_name'] .'/edit');
-        $form[$key]['remove']['#value'] = l(t('remove'), 'admin/content/types/'. $type['url_str'] .'/fields/'. $field['field_name'] .'/remove');
-        $form[$key]['weight'] = array('#type' => 'weight', '#default_value' => $field['widget']['weight']);
-        $form[$key]['parent'] = array('#type' => 'select', '#options' => $group_options, '#default_value' => '');
-        $form[$key]['hidden_name'] = array('#type' => 'hidden', '#default_value' => $field['field_name']);
-        $form[$key]['#leaf'] = TRUE;
-      }
-      else {
-        $form[$key]['label']['#value'] = $key == 'body_filter' ? t('body') : $key;
-        $form[$key]['name']['#value'] = $key;
-        $form[$key]['type']['#value'] = '';
-        $form[$key]['configure']['#value'] = '';
-        $form[$key]['remove']['#value'] = '';
-        $form[$key]['weight'] = array('#type' => 'weight', '#default_value' => $value['#weight']);
-        $form[$key]['parent'] = array('#type' => 'textfield', '#default_value' => '');
-        $form[$key]['hidden_name'] = array('#type' => 'hidden', '#default_value' => $key);
-        $form[$key]['#disabled'] = TRUE;
-        $form[$key]['#leaf'] = TRUE;
-      }
-    }
-  }
-
-  $form['submit'] = array('#type' => 'submit', '#value' => t('Update'));
-  return $form;
-}
-
-function theme_content_admin_field_overview_dnd_form($form) {
-  drupal_set_message('NOTE : This form is not functional yet - No settings will be saved.');
-  // The css for this form contains non-validating styles,
-  // so we use a separate file, included only on the relevant page.
-  drupal_add_css(drupal_get_path('module', 'content') .'/content_admin.css');
-
   $header = array(t('Label'), t('Name'), t('Type'), t('Weight'), array('data' => t('Operations'), 'colspan' => 2));
   $rows = array();
 
-  // The table was created in the form
-  // iterate through it and render form elements when placeholders are encountered
-  // then run the rows array through theme_table().
-  foreach (element_children($form) as $key) {
+  foreach ($form['#order'] as $key) {
+    $row = array();
     $element = &$form[$key];
-    if (isset($element['configure'])) {
-      $row = array();
-      $element['weight']['#attributes']['class'] = 'field-weight';
-      $element['parent']['#attributes']['class'] = 'group-parent';
-      $element['hidden_name']['#attributes']['class'] = 'field-name';
-      $row[] = theme('indentation', isset($element['#depth']) ? $element['#depth'] : 0) . drupal_render($element['label']);
-      $row[] = drupal_render($element['name']);
-      $row[] = drupal_render($element['type']);
-      $row[] = drupal_render($element['weight']) . drupal_render($element['parent']) . drupal_render($element['hidden_name']);
-      $row[] = drupal_render($element['configure']);
-      $row[] = drupal_render($element['remove']);
-      $class = isset($element['#disabled']) ? 'content-field-overview-disabled' : 'content-field-overview-enabled draggable';
-      $class .= isset($element['#leaf']) ? ' tabledrag-leaf' : '';
-      $class .= isset($element['#root']) ? ' tabledrag-root' : '';
-      $rows[] = array('data' => $row, 'class' => $class);
-
-    }
+    $element['weight']['#attributes']['class'] = 'field-weight';
+    $element['parent']['#attributes']['class'] = 'group-parent';
+    $element['hidden_name']['#attributes']['class'] = 'field-name';
+    if (in_array($key, $form['#groups'])) {
+      $element['label']['#prefix'] = '<b>';
+      $element['label']['#suffix'] = '</b>';
+    }
+    $row[] = theme('indentation', isset($element['#depth']) ? $element['#depth'] : 0) . drupal_render($element['label']);
+    $row[] = drupal_render($element['name']);
+    $row[] = drupal_render($element['type']);
+    $row[] = drupal_render($element['weight']) . drupal_render($element['parent']) . drupal_render($element['hidden_name']);
+    $row[] = drupal_render($element['configure']);
+    $row[] = drupal_render($element['remove']);
+    $class = 'draggable';
+    $class .= isset($element['#disabled']) ? ' menu-disabled' : '';
+    $class .= isset($element['#leaf']) ? ' tabledrag-leaf' : '';
+    $class .= isset($element['#root']) ? ' tabledrag-root' : '';
+    $rows[] = array('data' => $row, 'class' => $class);
   }
+
   $output  = theme('table', $header, $rows, array('id' => 'content-field-overview'));
   $output .= drupal_render($form);
+
   drupal_add_tabledrag('content-field-overview', 'match', 'parent', 'group-parent', 'group-parent', 'field-name', TRUE, 1);
   drupal_add_tabledrag('content-field-overview', 'order', 'sibling', 'field-weight');
 
@@ -450,11 +180,23 @@
   $form_values = $form_state['values'];
 
   // Update field weights.
-  foreach ((array) $form_values['field-weights'] as $key => $value) {
-    if ($key && !in_array($key, unserialize($form_values['disabled']))) {
+  $extra = array();
+  foreach ($form_values as $key => $value) {
+    // Groups are handled in fieldgroup_content_overview_form_submit().
+    if (in_array($key, $form['#fields'])) {
       db_query("UPDATE {". content_instance_tablename() ."} SET weight = %d WHERE type_name = '%s' AND field_name = '%s'",
-        $value, $form_values['type_name'], $key);
+        $value['weight'], $form['#type_name'], $key);
     }
+    elseif (in_array($key, $form['#extra'])) {
+      $extra[$key] = $value['weight'];
+    }
+  }
+
+  if ($extra) {
+    variable_set('content_extra_weights_'. $form['#type_name'], $extra);
+  }
+  else {
+    variable_del('content_extra_weights_'. $form['#type_name']);
   }
 
   content_clear_type_cache();
Index: content_crud.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/content_crud.inc,v
retrieving revision 1.52
diff -u -r1.52 content_crud.inc
--- content_crud.inc	10 Dec 2007 23:19:59 -0000	1.52
+++ content_crud.inc	26 Dec 2007 11:57:38 -0000
@@ -543,6 +543,12 @@
       drupal_set_message(t('Content fields table %old_name has been renamed to %new_name and field instances have been updated.', array(
         '%old_name' => $old_name, '%new_name' => $new_name)));
     }
+
+    // Rename the variable storing weights for non-CCK fields.
+    if ($extra = variable_get('content_extra_weights_'. $info->old_type, array())) {
+      variable_set('content_extra_weights_'. $info->type, $extra);
+      variable_del('content_extra_weights_'. $info->old_type);
+    }
   }
   // Reset all content type info and alter the menu paths.
   content_menu_needs_rebuild(TRUE);
Index: fieldgroup.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/fieldgroup.module,v
retrieving revision 1.62
diff -u -r1.62 fieldgroup.module
--- fieldgroup.module	27 Nov 2007 14:47:23 -0000	1.62
+++ fieldgroup.module	26 Dec 2007 11:57:57 -0000
@@ -286,7 +286,7 @@
 function _fieldgroup_groups_label($content_type) {
   $groups = fieldgroup_groups($content_type);
 
-  $labels[0] = t('No group');
+  $labels[''] = t('No group');
   foreach ($groups as $group_name => $group) {
     $labels[$group_name] = t($group['label']);
   }
@@ -361,24 +361,21 @@
 }
 
 function fieldgroup_content_overview_form_submit($form, &$form_state) {
-  // Update groups.
   $form_values = $form_state['values'];
-  if (isset($form_values['field-groups'])) {
-    foreach ((array) $form_values['field-groups'] as $key => $value) {
-      if ($key && !in_array($key, unserialize($form_values['disabled']))) {
-        fieldgroup_update_fields(array('field_name' => $key, 'group' => $value, 'type_name' => $form_values['type_name']));
-      }
-    }
-  }
-  // Update group weights.
-  if (isset($form_values['group-weights'])) {
-    foreach ((array) $form_values['group-weights'] as $key => $value) {
-      if ($key && !in_array($key, unserialize($form_values['disabled']))) {
-        db_query("UPDATE {". fieldgroup_tablename() ."} SET weight = %d WHERE type_name = '%s' AND group_name = '%s'",
-        $value, $form_values['type_name'], $key);
-      }
+  $type_name = $form['#type_name'];
+  // Update field weights.
+  $extra = array();
+  foreach ($form_values as $key => $value) {
+    if (in_array($key, $form['#fields'])) {
+      // TODO : check the parent group does exist ?
+      fieldgroup_update_fields(array('field_name' => $key, 'group' => $value['parent'], 'type_name' => $type_name));
+    }
+    elseif (in_array($key, $form['#groups'])) {
+      db_query("UPDATE {". fieldgroup_tablename() ."} SET weight = %d WHERE type_name = '%s' AND group_name = '%s'",
+        $value['weight'], $type_name, $key);
     }
   }
+
   cache_clear_all('fieldgroup_data', content_cache_tablename());
 }
 

