Index: auto_nodetitle.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/auto_nodetitle/auto_nodetitle.module,v
retrieving revision 1.4.2.14
diff -u -r1.4.2.14 auto_nodetitle.module
--- auto_nodetitle.module	7 Apr 2007 15:25:20 -0000	1.4.2.14
+++ auto_nodetitle.module	4 Oct 2007 15:45:47 -0000
@@ -5,6 +5,10 @@
  * @file
  * Allows hiding of the node title field and automatic title creation
  */
+ 
+define('AUTO_NODETITLE_DISABLED', 0);
+define('AUTO_NODETITLE_ENABLED', 1);
+define('AUTO_NODETITLE_OPTIONAL', 2);
 
 /**
  * Implementation of hook_perm()
@@ -23,12 +27,16 @@
   }
   else if (isset($form['#node']) && isset($form['#post']) && $form['#node']->type .'_node_form' == $form_id) {
     //this is a node form    
-    if (variable_get('ant_'. $form['#node']->type, 0)) {
+    if (auto_nodetitle_get_setting($form['#node']->type) == AUTO_NODETITLE_ENABLED) {
       // we will autogenerate the title later, just hide the title field in the meanwhile
       $form['title']['#value'] = 'ant';
       $form['title']['#type'] = 'value';
       $form['title']['#required'] = FALSE;
     }
+    else if (auto_nodetitle_get_setting($form['#node']->type) == AUTO_NODETITLE_OPTIONAL) {
+      // we will make the title optional
+      $form['title']['#required'] = FALSE;
+    }
   }
 }
 
@@ -36,17 +44,19 @@
  * Implementation of hook_nodeapi().
  */
 function auto_nodetitle_nodeapi(&$node, $op, $form = NULL, $a4 = NULL) {
-  if ($op == 'validate' && variable_get('ant_'. $node->type, 0)) {
-    /*
-     * Sets the node title.
-     * We need to do this on validation because of two points: 
-     *     It's early engouh to have node previews working and 
-     *     it's late enough as CCK has already gone through the 'process form values' step 
-     * 
-     * As changes to $node are not persistent during validation, we use form_set_value()!
-     */
-    auto_nodetitle_set_title($node);
-    form_set_value($form['title'], $node->title);
+  if ($op == 'validate') {
+    if ((auto_nodetitle_get_setting($node->type) == AUTO_NODETITLE_ENABLED) || ((auto_nodetitle_get_setting($node->type) == AUTO_NODETITLE_OPTIONAL) && empty($node->title))) {
+      /*
+       * Sets the node title.
+       * We need to do this on validation because of two points: 
+       *     It's early engouh to have node previews working and 
+       *     it's late enough as CCK has already gone through the 'process form values' step 
+       * 
+       * As changes to $node are not persistent during validation, we use form_set_value()!
+       */
+      auto_nodetitle_set_title($node);
+      form_set_value($form['title'], $node->title);
+    }
   }
 }
 
@@ -108,9 +118,13 @@
     '#collapsed' => TRUE,
   );
   $form['auto_nodetitle']['ant'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Automatically generate the node title and hide the node title field.'),
-    '#default_value' => variable_get('ant_'. $form['#node_type']->type, 0),
+    '#type' => 'radios',
+    '#default_value' => auto_nodetitle_get_setting($form['#node_type']->type),
+    '#options' => array(
+      t('Disabled'),
+      t('Automatically generate the node title and hide the node title field'),
+      t('Automatically generate the node title if the title field is left empty'),
+    )
   );
 
   if (module_exists('token') || user_access('use PHP for title patterns')) {
@@ -155,3 +169,10 @@
     );
   }
 }
+
+/**
+ * Gets the auto node title setting associated with the given content type. 
+ */ 
+function auto_nodetitle_get_setting($type) {
+  return variable_get('ant_'. $type, AUTO_NODETITLE_DISABLED);
+}
