Index: flexinode.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flexinode/flexinode.module,v
retrieving revision 1.53
diff -u -r1.53 flexinode.module
--- flexinode.module	14 Sep 2005 12:39:07 -0000	1.53
+++ flexinode.module	27 Sep 2005 13:58:23 -0000
@@ -231,16 +231,16 @@
   foreach ($ctype->fields as $field) {
     $output .= flexinode_invoke('search_form', $field);
   }
-  
+
   $output = form_group(t('Content of post'), $output);
-  
+
   //renders the taxonomy selections
   foreach (taxonomy_get_vocabularies('flexinode-'. $ctype_id) as $vocabulary) {
     $taxonomy_form .= taxonomy_form($vocabulary->vid, 0, t('Optionally select a classification'), 'taxonomy]['.$vocabulary->vid);
   }
 
   $output .= $taxonomy_form ? form_group(t('Categories'), $taxonomy_form): NULL;
-  
+
   $output .= form_submit(t('Search'));
 
   $output .= $results;
@@ -479,9 +479,16 @@
     $ctype = flexinode_load_content_type($ctype->ctype_id);
     $rows[] = array(t($ctype->name), $ctype->description, l(t('edit content type'), 'admin/node/types/edit_type/' . $ctype->ctype_id));
 
-    $data = t('Title') . '<br />';
+    $data = '';
     foreach ($ctype->fields as $field) {
+    	if (!$row_count) {
+    		$data = '<strong>' . t('Title field:') . '</strong><br />';
+    	}
       $data .= t($field->label) . ' (' . l(t('edit field'), 'admin/node/types/edit_field/' . $field->field_id) . ')<br />';
+      if (!$row_count) {
+      	$data .= '<br />';
+      	$row_count++;
+      }
     }
 
     $url = 'admin/node/types/add_field/'.  $ctype->ctype_id;
@@ -519,7 +526,7 @@
  */
 function flexinode_access($op, $node) {
   global $user;
-  
+
   if ($op == 'create') {
     return user_access('create '. flexinode_node_name($node->type) .' content');
   }
@@ -644,12 +651,12 @@
 function flexinode_validate(&$node) {
   if (isset($node->ctype_id)) {
     $ctype = flexinode_load_content_type($node->ctype_id);
-  
+
     $error = array();
     foreach ($ctype->fields as $field) {
       $fieldname = 'flexinode_'. $field->field_id;
       $error[$fieldname] = '';
-      
+
       $validation = flexinode_invoke('validate', $field, $node);
       if ($validation) {
         $node->$fieldname = $validation['value'];
@@ -657,17 +664,17 @@
           $error[$fieldname] .= $validation['error'];
         }
       }
-  
+
       if ($field->required && !$node->$fieldname) {
         $error[$fieldname] .= t('You must fill in the field "'. $field->label .'".');
       }
-      
+
       if ($error[$fieldname] == '') unset($error[$fieldname]);
     }
-  
+
     // Pre-render the body and teaser fields, so the Drupal search works.
     $node = flexinode_content($node);
-   
+
     foreach ($error as $name => $message) {
       form_set_error($name, $message);
     }
@@ -821,7 +828,8 @@
   $ctype = db_fetch_object(db_query('SELECT * FROM {flexinode_type} WHERE ctype_id = %d', $ctype_id));
 
   $ctype->fields = array();
-  $result = db_query('SELECT * FROM {flexinode_field} WHERE ctype_id = %d ORDER BY weight ASC, label ASC', $ctype_id);
+  $result = db_query('SELECT * FROM {flexinode_field} WHERE ctype_id = %d ORDER BY is_title DESC, weight ASC, label ASC', $ctype_id);
+
   while ($field = db_fetch_object($result)) {
     $field->options = unserialize($field->options);
     $ctype->fields[] = $field;
@@ -926,6 +934,8 @@
     $ctype_id = db_next_id('{flexinode_ctype}');
 
     db_query("INSERT INTO {flexinode_type} (name, description, help, ctype_id) VALUES ('%s', '%s', '%s', %d)", $edit['name'], $edit['description'], $edit['help'], $ctype_id);
+		$field_id = db_next_id('{flexinode_field}');
+		db_query("INSERT INTO {flexinode_field} (field_id, ctype_id, label, field_type, options, description, is_title) VALUES (%d, %d, '%s', '%s', '%s', '%s', %d)", $field_id, $ctype_id, 'Title', 'textfield', serialize(array()), '', 1);
 
     drupal_set_message(t('created new content type "%name".', array('%name' => $edit['name'])));
   }
@@ -970,26 +980,31 @@
  * Generate a form for the editing of a content type field.
  */
 function flexinode_edit_field($edit) {
-  $form = form_textfield(t('Field label'), 'label', $edit['label'], 60, 128, '', NULL, TRUE);
-
-  $form .= form_textfield(t('Description'), 'description', $edit['description'], 60, 128, t('A brief description of the field, to be displayed on the content submission form.'));
-
-  $field->field_type = $edit['field_type'];
-  $form .= flexinode_invoke('config', $field, $edit);
+  $form = form_textfield(t('Title field label'), 'label', $edit['label'], 60, 128, 'You can provide a descriptive title label appropriate for the kind of content your flexinode content will store.<br />Examples: "Book title," "Song name," "Headline," etc.', NULL, TRUE);
 
-  $form .= form_checkbox(t('Required field'), 'required', 1, $edit['required'], t('Whether the user must fill in the field when creating content.'));
-  $form .= form_checkbox(t('Show in teaser'), 'show_teaser', 1, $edit['show_teaser'], t('Whether this field should be shown as part of the teaser.'));
-  $form .= form_checkbox(t('Show in table'), 'show_table', 1, $edit['show_table'], t('Whether this field should be shown as part of this content type\'s <a href="%table">tabular view</a>.', array('%table' => url('flexinode/table/'. $edit['ctype_id']))));
-  $form .= form_weight(t('Weight'), 'weight', $edit['weight'], 10, t('Optional. On the content editing form, the heavier fields will sink and the lighter fields will be positioned nearer the top.'));
+	// Show all fields if it is not the title field
+  if (!$edit['is_title']) {
+	  $form .= form_textfield(t('Description'), 'description', $edit['description'], 60, 128, t('A brief description of the field, to be displayed on the content submission form.'));
+	  $field->field_type = $edit['field_type'];
+	  $form .= flexinode_invoke('config', $field, $edit);
+	  $form .= form_checkbox(t('Required field'), 'required', 1, $edit['required'], t('Whether the user must fill in the field when creating content.'));
+	  $form .= form_checkbox(t('Show in teaser'), 'show_teaser', 1, $edit['show_teaser'], t('Whether this field should be shown as part of the teaser.'));
+	  $form .= form_checkbox(t('Show in table'), 'show_table', 1, $edit['show_table'], t('Whether this field should be shown as part of this content type\'s <a href="%table">tabular view</a>.', array('%table' => url('flexinode/table/'. $edit['ctype_id']))));
+	  $form .= form_weight(t('Weight'), 'weight', $edit['weight'], 10, t('Optional. On the content editing form, the heavier fields will sink and the lighter fields will be positioned nearer the top.'));
+	}
 
   $form .= form_submit(t('Submit'));
   if ($edit['field_id']) {
-    $form .= form_submit(t('Delete'));
+    // Hide delete button for the title field.  This field cannot be deleted.
+    if (!$edit['is_title']) {
+    	$form .= form_submit(t('Delete'));
+    }
     $form .= form_hidden('field_id', $edit['field_id']);
   }
 
   $form .= form_hidden('ctype_id', $edit['ctype_id']);
   $form .= form_hidden('field_type', $edit['field_type']);
+  $form .= form_hidden('is_title', $edit['is_title']);
 
   return form($form);
 }
@@ -1012,6 +1027,12 @@
  * Save a custom field to the database.
  */
 function flexinode_save_field($edit) {
+	if ($edit['is_title']) {
+		db_query("UPDATE {flexinode_field} SET label = '%s' WHERE field_id = %d", $edit['label'], $edit['field_id']);
+		drupal_set_message(t('updated title label'));
+		return $edit['field_id'];
+	}
+
   $options = array(0 => 0); // Placeholder for "none" option.
   if (!empty($edit['options'])) {
     foreach ($edit['options'] as $option) {
@@ -1158,7 +1179,7 @@
   $nodes = pager_query(db_rewrite_sql($sql), 20);
   while ($res = db_fetch_object($nodes)) {
     if ($node = node_load(array('nid' => $res->nid))) {
-      $entry = array('link' => url('node/'. $item), 
+      $entry = array('link' => url('node/'. $item),
                     'type' => node_invoke($node, 'node_name'),
                     'title' => $node->title,
                     'user' => format_name($node),
@@ -1179,7 +1200,7 @@
   }
 
   watchdog('search', t('Search: %keys (%type).', array('%keys' => theme('placeholder', $keys), '%type' => node_invoke($node, 'node_name'))), WATCHDOG_NOTICE);
-  
+
   return theme('page', $again . $output);
 }
 
