? .DS_Store
? content_types.diff
Index: webform.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.module,v
retrieving revision 1.136
diff -u -p -r1.136 webform.module
--- webform.module	20 Jun 2009 23:04:58 -0000	1.136
+++ webform.module	5 Jul 2009 15:03:51 -0000
@@ -304,7 +304,7 @@ function webform_menu_load($nid) {
     return FALSE;
   }
   $node = node_load($nid);
-  if (!isset($node->type) || $node->type != 'webform') {
+  if (!isset($node->type) || ($node->type != 'webform' && !in_array($node->type, webform_variable_get('webform_node_types')))) {
     return FALSE;
   }
   return $node;
@@ -565,9 +565,33 @@ function webform_file_download($file) {
 }
 
 /**
- * Implementation of hook_insert().
+ * Implementation of hook_nodeapi().
  */
-function webform_insert($node) {
+function webform_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
+  if (!in_array($node->type, webform_variable_get('webform_node_types')) && $node->type != 'webform') {
+    return;
+  }
+  switch ($op) {
+    case 'insert':
+      webform_node_insert($node);
+      break;
+    case 'update':
+      webform_node_update($node);
+      break;
+    case 'delete':
+      webform_node_delete($node);
+      break;
+    case 'load':
+      return webform_node_load($node);
+    case 'view':
+      return webform_node_view($node, $a3, $a4);
+  }
+}
+
+/**
+ * Implementation of hook_node_insert().
+ */
+function webform_node_insert($node) {
   module_load_include('inc', 'webform', 'includes/webform.components');
 
   // Insert the Webform.
@@ -588,9 +612,9 @@ function webform_insert($node) {
 }
 
 /**
- * Implementation of hook_update().
+ * Implementation of hook_node_update().
  */
-function webform_update($node) {
+function webform_node_update($node) {
   // Update the webform by deleting existing data and replacing with the new.
   db_query('DELETE FROM {webform} WHERE nid = %d', $node->nid);
   db_query('DELETE FROM {webform_component} WHERE nid = %d', $node->nid);
@@ -601,7 +625,7 @@ function webform_update($node) {
 /**
  * Implementation of hook_delete().
  */
-function webform_delete(&$node) {
+function webform_node_delete(&$node) {
   // Allow components clean up extra data, such as uploaded files.
   module_load_include('inc', 'webform', 'includes/webform.components');
   foreach ($node->webform['components'] as $cid => $component) {
@@ -616,30 +640,27 @@ function webform_delete(&$node) {
   db_query('DELETE FROM {webform_submitted_data} WHERE nid = %d', $node->nid);
 }
 
-/**
- * Implementation of hook_load().
- */
-function webform_load($node) {
+function webform_node_load($node) {
   module_load_include('inc', 'webform', 'includes/webform.components');
-  $additions = new stdClass();
+  $additions = array();
 
   if ($webform = db_fetch_array(db_query('SELECT * FROM {webform} WHERE nid = %d', $node->nid))) {
-    $additions->webform = $webform;
+    $additions['webform'] = $webform;
 
-    $additions->webform['roles'] = array();
+    $additions['webform']['roles'] = array();
     $result = db_query('SELECT rid FROM {webform_roles} WHERE nid = %d', $node->nid);
     while ($role = db_fetch_object($result)) {
-      $additions->webform['roles'][] = $role->rid;
+      $additions['webform']['roles'][] = $role->rid;
     }
 
-    $additions->webform['emails'] = array();
+    $additions['webform']['emails'] = array();
     $result = db_query('SELECT * FROM {webform_emails} WHERE nid = %d', $node->nid);
     while ($email = db_fetch_array($result)) {
-      $additions->webform['emails'][$email['eid']] = $email;
+      $additions['webform']['emails'][$email['eid']] = $email;
     }
   }
   else {
-    $additions->webform = array(
+    $additions['webform'] = array(
       'confirmation' => '',
       'confirmation_format' => FILTER_FORMAT_DEFAULT,
       'teaser' => 0,
@@ -654,11 +675,11 @@ function webform_load($node) {
     );
   }
 
-  $additions->webform['components'] = array();
-  $additions->webform['additional_emails'] = array();
+  $additions['webform']['components'] = array();
+  $additions['webform']['additional_emails'] = array();
   $result = db_query('SELECT * FROM {webform_component} WHERE nid = %d ORDER BY weight, name', $node->nid);
   while ($c = db_fetch_array($result)) {
-    $component =& $additions->webform['components'][$c['cid']];
+    $component =& $additions['webform']['components'][$c['cid']];
     $component['nid'] = $node->nid;
     $component['cid'] = $c['cid'];
     $component['form_key'] = $c['form_key'] ? $c['form_key'] : $c['cid'];
@@ -671,18 +692,18 @@ function webform_load($node) {
     $component['pid'] = $c['pid'];
     $component['weight'] = $c['weight'];
     if (isset($component['extra']['email']) && $component['extra']['email']) {
-      $additions->webform['additional_emails'][$c['cid']] = $c['cid'];
+      $additions['webform']['additional_emails'][$c['cid']] = $c['cid'];
     }
 
     webform_component_defaults($component);
   }
 
   // Organize the components into a fieldset-based order.
-  if (!empty($additions->webform['components'])) {
+  if (!empty($additions['webform']['components'])) {
     $component_tree = array();
     $page_count = 1;
-    _webform_components_tree_build($additions->webform['components'], $component_tree, 0, $page_count);
-    $additions->webform['components'] = _webform_components_tree_flatten($component_tree['children']);
+    _webform_components_tree_build($additions['webform']['components'], $component_tree, 0, $page_count);
+    $additions['webform']['components'] = _webform_components_tree_flatten($component_tree['children']);
   }
   return $additions;
 }
@@ -711,21 +732,8 @@ function webform_link($type, $node = NUL
  * Creates the standard form for editing or creating a webform.
  */
 function webform_form(&$node, &$form_state) {
-  // Set node defaults if empty.
-  if (!isset($node->nid) && !isset($node->webform)) {
-    $node->nid = 0;
-    $additions = webform_load($node);
-    $node->webform = $additions->webform;
-    $node->nid = NULL;
-  }
-
   $form = node_content_form($node, $form_state);
 
-  $form['webform'] = array(
-    '#type' => 'value',
-    '#value' => $node->webform,
-  );
-
   return $form;
 }
 
@@ -733,8 +741,30 @@ function webform_form(&$node, &$form_sta
  * Implementation of hook_form_alter().
  */
 function webform_form_alter(&$form, $form_state, $form_id) {
-  if ($form_id == 'webform_node_form' && empty($form['nid']['#value'])) {
-    $form['buttons']['submit']['#submit'][] = 'webform_form_submit';
+  $webforms = webform_variable_get('webform_node_types');
+  $webforms[] = 'webform';
+  if (in_array($form['#node']->type, $webforms)) {
+    if ($form_id == $form['#node']->type .'_node_form') {
+      if (empty($form['nid']['#value'])) {
+        $form['buttons']['submit']['#submit'][] = 'webform_form_submit';
+        if (!isset($form['#node']->webform)) {
+          $node = $form['#node'];
+          $node->nid = 0;
+          $additions = module_invoke('webform', 'nodeapi', $node, 'load');
+          $form['webform'] = array(
+            '#type' => 'value',
+            '#value' => $additions['webform'],
+          );
+        }
+      }
+      else {
+        $node = $form['#node'];
+        $form['webform'] = array(
+          '#type' => 'value',
+          '#value' => $node->webform,
+        );
+      }
+    }
   }
 }
 
@@ -750,15 +780,13 @@ function webform_form_submit($form, &$fo
 }
 
 /**
- * Implementation of hook_view().
+ * Implementation of hook_node_view().
  */
-function webform_view(&$node, $teaser = 0, $page = 0) {
+function webform_node_view(&$node, $teaser, $page) {
   global $user;
-
   // If a teaser, do not display the form.
   if ($teaser && !$node->webform['teaser']) {
     $node->content['teaser'] = array('#value' => check_markup($node->teaser, $node->format, FALSE));
-    return $node;
   }
 
   $submission = array();
@@ -827,8 +855,6 @@ function webform_view(&$node, $teaser = 
   if (isset($output)) {
     $node->content['webform'] = array('#value' => $output, '#weight' => 1);
   }
-
-  return $node;
 }
 
 /**
@@ -932,6 +958,21 @@ function webform_mail($key, &$message, $
  * Menu callback for admin/webform/settings.
  */
 function webform_admin_settings() {
+  $types = node_get_types();
+  foreach ($types as $type) {
+    if ($type->type != 'webform') {
+      $type_options[$type->type] = $type->name;
+    }
+  }
+  $default_types = webform_variable_get('webform_node_types');
+  $form['node_types'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Webform Node Types'),
+    '#description' => t('Webform allows you to enable the webform components for any content type.  Choose the types on which you would like to associate webform components.'),
+    '#options' => $type_options,
+    '#default_value' => $default_types,
+  );
+
   module_load_include('inc', 'webform', 'includes/webform.export');
 
   $form['components'] = array(
@@ -1052,10 +1093,20 @@ function webform_admin_settings() {
 
   $form = system_settings_form($form);
   $form['#theme'] = 'webform_admin_settings';
+  $form['#submit'][] = 'webform_admin_settings_submit';
 
   return $form;
 }
 
+function webform_admin_settings_submit($form, &$form_state) {
+  foreach ($form_state['values']['node_types'] as $type) {
+    if ($type) {
+      $types[] = $type;
+    }
+  }
+  variable_set('webform_node_types', $types);
+}
+
 function theme_webform_admin_settings($form) {
   // Format the components into a table.
   foreach (element_children($form['components']) as $key) {
@@ -1933,6 +1984,9 @@ function webform_variable_get($variable)
     case 'webform_default_subject':
       $result = variable_get('webform_default_subject', t('Form submission from: %title'));
       break;
+    case 'webform_node_types':
+      $result = variable_get('webform_node_types', array());
+      break;
   }
   return $result;
 }
