? nodeapi_example.patch
Index: nodeapi_example.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/docs/developer/examples/nodeapi_example.module,v
retrieving revision 1.4
diff -u -p -r1.4 nodeapi_example.module
--- nodeapi_example.module	23 Jul 2006 02:32:53 -0000	1.4
+++ nodeapi_example.module	7 Nov 2006 21:26:48 -0000
@@ -8,35 +8,7 @@
  *
  * We will add the ability for each node to have a "rating," which will be a
  * number from one to five.
- *
- * To store this extra information, we need an auxiliary database table.
- * The nodeapi_example.install file can create this table for you.
- *
- * Database definition:
- * @code
- *   CREATE TABLE nodeapi_example (
- *     nid int(10) unsigned NOT NULL default '0',
- *     rating int(10) unsigned NOT NULL default '0',
- *     PRIMARY KEY (nid)
- *   )
- * @endcode
- */
-
-/**
- * Implementation of hook_help().
- *
- * Throughout Drupal, hook_help() is used to display help text at the top of
- * pages. Some other parts of Drupal pages get explanatory text from these hooks
- * as well. We use it here to provide a description of the module on the
- * module administration page.
  */
-function nodeapi_example_help($section) {
-  switch ($section) {
-    case 'admin/modules#description':
-      // This description is shown in the listing at admin/modules.
-      return t('An example module showing how to extend existing content types.');
-  }
-}
 
 /**
  * Implementation of hook_form_alter().
@@ -46,17 +18,20 @@ function nodeapi_example_help($section) 
  */
 function nodeapi_example_form_alter($form_id, &$form) {
   // We're only modifying node forms, if the type field isn't set we don't need
-  // to bother.
-  if (!isset($form['type'])) {
+  // to bother; otherwise, store it for later retrieval.
+  if (isset($form['type'])) {
+    $type = $form['type']['#value'];
+  }
+  elseif (isset($form['orig_type'])) {
+    $type = $form['orig_type']['#value'];
+  }
+  else {
     return;
   }
 
-  // Make a copy of the type to shorten up the code
-  $type =  $form['type']['#value'];
-
   // The rating is enabled on a per node type basis. The variable used to store
   // this information is named named using both the name of this module, to
-  // avoid namespace conflicts, and the node, because we support multiple node
+  // avoid namespace conflicts, and the node type, because we support multiple node
   // types.
   $enabled = variable_get('nodeapi_example_'. $type, 0);
 
@@ -65,7 +40,7 @@ function nodeapi_example_form_alter($for
     // types should have our rating field added. This is done by inserting a
     // checkbox in the node's content type configuration page. The variable will
     // be automatically saved by the settings form.
-    case $type .'_node_settings':
+    case 'node_type_form':
       $form['workflow']['nodeapi_example_'. $type] = array(
         '#type' => 'radios',
         '#title' => t('NodeAPI Example Rating'),
@@ -73,8 +48,7 @@ function nodeapi_example_form_alter($for
         '#options' => array(0 => t('Disabled'), 1 => t('Enabled')),
         '#description' => t('Should this node have a rating attached to it?'),
       );
-      break;
-
+    break;
     case $type .'_node_form':
       // If the rating is enabled for this node type, we insert our control
       // into the form.
@@ -89,7 +63,7 @@ function nodeapi_example_form_alter($for
           '#weight' => 0,
         );
       }
-      break;
+    break;
   }
 }
 
@@ -155,8 +129,10 @@ function nodeapi_example_nodeapi(&$node,
     // filters transform user-supplied content, whereas we are extending it with
     // additional information.
     case 'view':
-      $node->body = theme('nodeapi_example_rating', $node->nodeapi_example_rating) . $node->body;
-      $node->teaser = theme('nodeapi_example_rating', $node->nodeapi_example_rating) . $node->teaser;
+      $node->content['nodeapi_example'] = array(
+        '#value' => theme('nodeapi_example_rating', $node->nodeapi_example_rating),
+        '#weight' => -1,
+      );
       break;
   }
 }
