Index: docs/developer/examples/node_example.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/docs/developer/examples/node_example.module,v
retrieving revision 1.15
diff -u -r1.15 node_example.module
--- docs/developer/examples/node_example.module	12 Dec 2005 20:42:43 -0000	1.15
+++ docs/developer/examples/node_example.module	21 Feb 2006 22:48:01 -0000
@@ -13,10 +13,10 @@
  * Database definition:
  * @code
  *   CREATE TABLE node_example (
- *     nid int(10) unsigned NOT NULL default '0',
+ *     vid int(10) unsigned NOT NULL default '0',
  *     color varchar(255) NOT NULL default '',
  *     quantity int(10) unsigned NOT NULL default '0',
- *     PRIMARY KEY  (nid)
+ *     PRIMARY KEY (vid)
  *   )
  * @endcode
  */
@@ -133,20 +133,19 @@
  */
 function node_example_form(&$node) {
   $form['title'] = array('#type' => 'textfield', '#title' => t('Title'),
-    '#size' => 60, '#maxlength' => 128, '#required' => TRUE,
-    '#default_value' => $node->title);
-  $form['body'] = array('#type' => 'textarea', '#title' => t('Body'),
-    '#default_value' => $node->body, '#required' => FALSE );
+    '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5);
+  $form['body_filter']['body'] = array('#type' => 'textarea',
+    '#title' => t('Body'), '#default_value' => $node->body,
+    '#required' => FALSE);
+  $form['body_filter']['filter'] = filter_form($node->format);
 
   // Now we define the form elements specific to our node type.
   $form['color'] = array('#type' => 'textfield', '#title' => t('Color'),
-    '#default_value' => $node->color, '#size' =>  60, '#maxlength' => 128,
-    '#weight' => 0);
+    '#default_value' => $node->color);
   $form['quantity'] = array('#type' => 'textfield', '#title' => t('Quantity'),
-    '#default_value' => $node->quantity, '#size' =>  10, '#maxlength' => 10,
-    '#weight' => 1);
+    '#default_value' => $node->quantity, '#size' => 10, '#maxlength' => 10);
 
-  return array_merge($form, filter_form($node->format));
+  return $form;
 }
 
 /**
@@ -177,7 +176,7 @@
  * database inserts.
  */
 function node_example_insert($node) {
-  db_query("INSERT INTO {node_example} (nid, color, quantity) VALUES (%d, '%s', %d)", $node->nid, $node->color, $node->quantity);
+  db_query("INSERT INTO {node_example} (vid, color, quantity) VALUES (%d, '%s', %d)", $node->vid, $node->color, $node->quantity);
 }
 
 /**
@@ -187,7 +186,13 @@
  * database updates.
  */
 function node_example_update($node) {
-  db_query("UPDATE {node_example} SET color = '%s', quantity = %d WHERE nid = %d", $node->color, $node->quantity, $node->nid);
+  // if this is a new node or we're adding a new revision,
+  if ($node->revision) {
+    node_example_insert($node);
+  }
+  else {
+    db_query("UPDATE {node_example} SET color = '%s', quantity = %d WHERE vid = %d", $node->color, $node->quantity, $node->vid);
+  }
 }
 
 /**
@@ -199,6 +204,10 @@
   db_query('DELETE FROM {node_example} WHERE nid = %d', $node->nid);
 }
 
+//
+// T O D O : NEED TO DELETE REVISIONS!
+// 
+
 /**
  * Implementation of hook_load().
  *
@@ -207,7 +216,7 @@
  * every time a node is loaded, and allows us to do some loading of our own.
  */
 function node_example_load($node) {
-  $additions = db_fetch_object(db_query('SELECT color, quantity FROM {node_example} WHERE nid = %d', $node->nid));
+  $additions = db_fetch_object(db_query('SELECT color, quantity FROM {node_example} WHERE vid = %d', $node->vid));
   return $additions;
 }
 

