Index: modules/node/content_types.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/content_types.inc,v
retrieving revision 1.18
diff -u -p -r1.18 content_types.inc
--- modules/node/content_types.inc	5 Dec 2006 05:47:37 -0000	1.18
+++ modules/node/content_types.inc	9 Dec 2006 03:56:46 -0000
@@ -52,6 +52,18 @@ function node_overview_types() {
 
 /**
  * Generates the node type editing form.
+ *
+ * Modules that wish to respond to the addition, update, or deletion of node
+ * types should implement hook_node_type.
+ *
+ * Elements added to this form using hook_form_alter (for example, the comment
+ * options radios added by the comment module) will automatically be saved as
+ * persistent variables, in a similar fashion as occurs with a system settings
+ * form. These variables will be named as 'key_type' where key is the array key
+ * of the form value and type is the machine-readable name of the content type.
+ * Renaming and deleting these variables occurs automatically if the content
+ * type is renamed or deleted.  To avoid this automatic saving, add the
+ * relevant form values' keys to the 'node_type_excluded_keys' form element.
  */
 function node_type_form($type = NULL) {
   if (!isset($type->type)) {
@@ -168,7 +180,7 @@ function node_type_form($type = NULL) {
 
   $form['old_type'] = array(
     '#type' => 'value',
-    '#value' => $type->type,
+    '#value' => trim($type->type),
   );
   $form['orig_type'] = array(
     '#type' => 'value',
@@ -210,6 +222,10 @@ function node_type_form($type = NULL) {
       '#value' => t('Reset to defaults'),
     );
   }
+  $form['node_type_excluded_keys']['#type'] = 'value';
+  // If keys are added to this array, the corresponding elements in the form
+  // values will not be saved as persistent variables by node_type_submit().
+  $form['node_type_excluded_keys']['#value'] = array_merge(array_keys($form), array_keys($form['submission']), array_keys($form['identity']));
 
   return $form;
 }
@@ -223,7 +239,7 @@ function node_type_form_validate($form_i
   $type->name = trim($form_values['name']);
 
   // Work out what the type was before the user submitted this form
-  $old_type = trim($form_values['old_type']);
+  $old_type = $form_values['old_type'];
   if (empty($old_type)) {
     $old_type = $type->type;
   }
@@ -243,7 +259,6 @@ function node_type_form_validate($form_i
 
   if (isset($names[$type->name]) && $names[$type->name] != $old_type) {
     form_set_error('name', t('The human-readable name %name is already taken.', array('%name' => $names[$type->name])));
-    break;
   }
 }
 
@@ -253,28 +268,21 @@ function node_type_form_validate($form_i
 function node_type_form_submit($form_id, $form_values) {
   $op = isset($form_values['op']) ? $form_values['op'] : '';
 
-  $type = new stdClass();
-
-  $type->type = trim($form_values['type']);
-  $type->name = trim($form_values['name']);
-  $type->orig_type = trim($form_values['orig_type']);
-  $type->old_type = isset($form_values['old_type']) ? $form_values['old_type'] : $type->type;
-
-  $type->description = $form_values['description'];
-  $type->help = $form_values['help'];
-  $type->min_word_count = $form_values['min_word_count'];
-  $type->title_label = $form_values['title_label'];
-  $type->body_label = $form_values['body_label'];
-
+  $type = (object)$form_values;
+  $type->type = trim($type->type);
+  $type->name = trim($type->name);
   // title_label is required in core; has_title will always be true, unless a
   // module alters the title field.
   $type->has_title = ($type->title_label != '');
   $type->has_body = ($type->body_label != '');
-
-  $type->module = !empty($form_values['module']) ? $form_values['module'] : 'node';
-  $type->custom = $form_values['custom'];
   $type->modified = TRUE;
-  $type->locked = $form_values['locked'];
+
+  if (empty($type->old_type)) {
+    $type->old_type = $type->type;
+  }
+  if (empty($type->module)) {
+    $type->module = 'node';
+  }
 
   if ($op == t('Reset to defaults')) {
     node_type_reset($type);
@@ -285,18 +293,20 @@ function node_type_form_submit($form_id,
 
   $status = node_type_save($type);
 
-  // Remove everything that's been saved already - whatever's left is assumed
-  // to be a persistent variable.
-  foreach ($form_values as $key => $value) {
-    if (isset($type->$key)) {
-      unset($form_values[$key]);
-    }
+
+  // Remove everything that's marked to be excluded (saved already) -
+  // whatever's left is assumed to be a persistent variable.
+  $variables = $form_values;
+  foreach ($type->node_type_excluded_keys as $key) {
+    unset($variables[$key]);
   }
+  unset($variables['op'], $variables['form_token'], $variables['form_id']);
 
-  unset($form_values['type_display'], $form_values['old_type'], $form_values['orig_type'], $form_values['submit'], $form_values['delete'], $form_values['reset'], $form_values['form_id']);
+  //save the remaining keys for use when deleting a node type
+  variable_set('node_type_variables', array_keys($variables));
 
   // Save or reset persistent variable values.
-  foreach ($form_values as $key => $value) {
+  foreach ($variables as $key => $value) {
     $key .= '_'. $type->type;
     if ($op == t('Reset to defaults')) {
       variable_del($key);
@@ -360,10 +370,10 @@ function node_node_type($op, $info) {
  *   then nothing happens.
  */
 function node_type_reset(&$type) {
-  $info_array = module_invoke($type->module, 'node_info');
+  $info_array = module_invoke_all('node_info');
   if (isset($info_array[$type->orig_type])) {
-    $info = _node_type_set_defaults($info_array[$type->orig_type]);
     $info['type'] = $type->orig_type;
+    $info = _node_type_set_defaults($info_array[$type->orig_type]);
 
     foreach ($info as $field => $value) {
       $type->$field = $value;
Index: modules/node/node.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.module,v
retrieving revision 1.744
diff -u -p -r1.744 node.module
--- modules/node/node.module	8 Dec 2006 16:21:15 -0000	1.744
+++ modules/node/node.module	9 Dec 2006 03:56:49 -0000
@@ -299,6 +299,15 @@ function node_type_delete($type) {
 
   $info = node_get_types('type', $type);
   module_invoke_all('node_type', 'delete', $info);
+
+  // delete persistent variable values that were set by adding elements to the
+  // node type form.
+  $variables = variable_get('node_type_variables', array());
+
+  foreach ($variables as $key) {
+    $key .= '_'. $info->type;
+    variable_del($key);
+  }
 }
 
 /**
