### Eclipse Workspace Patch 1.0
#P webform
Index: includes/webform.pages.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/webform/includes/webform.pages.inc,v
retrieving revision 1.10.2.2
diff -u -r1.10.2.2 webform.pages.inc
--- includes/webform.pages.inc	19 Aug 2010 03:00:45 -0000	1.10.2.2
+++ includes/webform.pages.inc	30 Aug 2010 14:29:15 -0000
@@ -117,6 +117,12 @@
     '#collapsed' => TRUE,
     '#weight' => -1,
   );
+  $form['advanced']['block'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Available as block'),
+    '#default_value' => $node->webform['block'],
+    '#description' => t('If enabled this webform node will be available as a block.'),
+  );
   $form['advanced']['teaser'] = array(
     '#type' => 'checkbox',
     '#title' => t('Show complete form in teaser'),
@@ -193,6 +199,9 @@
   // Save roles.
   $node->webform['roles'] = array_keys(array_filter($form_state['values']['roles']));
 
+  // Set the block option.
+  $node->webform['block'] = $form_state['values']['block'];
+
   // Set the Show complete form in teaser setting.
   $node->webform['teaser'] = $form_state['values']['teaser'];
 
Index: webform.install
===================================================================
RCS file: /cvs/drupal/contributions/modules/webform/webform.install,v
retrieving revision 1.40.2.16
diff -u -r1.40.2.16 webform.install
--- webform.install	30 Aug 2010 00:30:29 -0000	1.40.2.16
+++ webform.install	30 Aug 2010 14:29:14 -0000
@@ -38,6 +38,13 @@
         'type' => 'varchar',
         'length' => 255,
       ),
+      'block' => array(
+         'description' => 'Boolean value for whether this form be available as a block.',
+         'type' => 'int',
+         'size' => 'tiny',
+         'not null' => TRUE,
+         'default' => '0',
+      ),
       'teaser' => array(
         'description' => 'Boolean value for whether the entire form should be displayed on the teaser.',
         'type' => 'int',
@@ -356,6 +363,7 @@
   variable_del('webform_default_from_name');
   variable_del('webform_default_subject');
   variable_del('webform_csv_delimiter');
+  variable_del('webform_blocks');
 
   $component_list = array();
   $path = drupal_get_path('module', 'webform') . '/components';
@@ -1181,6 +1189,15 @@
 }
 
 /**
+ * Add field for block feature.
+ */
+function webform_update_6319() {
+  $ret = array();
+  db_add_field($ret, 'webform', 'block', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => '0'));
+  return $ret;
+}
+
+/**
  * Recursively delete all files and folders in the specified filepath, then
  * delete the containing folder.
  *
Index: webform.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/webform/webform.module,v
retrieving revision 1.196.2.50
diff -u -r1.196.2.50 webform.module
--- webform.module	26 Aug 2010 11:56:37 -0000	1.196.2.50
+++ webform.module	30 Aug 2010 14:29:15 -0000
@@ -856,7 +856,13 @@
   module_load_include('inc', 'webform', 'includes/webform.emails');
 
   // Insert the webform.
-  db_query("INSERT INTO {webform} (nid, confirmation, confirmation_format, redirect_url, teaser, allow_draft, submit_notice, submit_text, submit_limit, submit_interval) VALUES (%d, '%s', %d, '%s', %d, %d, %d, '%s', %d, %d)", $node->nid, $node->webform['confirmation'], $node->webform['confirmation_format'], $node->webform['redirect_url'], $node->webform['teaser'], $node->webform['allow_draft'], $node->webform['submit_notice'], $node->webform['submit_text'], $node->webform['submit_limit'], $node->webform['submit_interval']);
+  db_query("INSERT INTO {webform} (nid, confirmation, confirmation_format, redirect_url, block, teaser, allow_draft, submit_notice, submit_text, submit_limit, submit_interval) VALUES (%d, '%s', %d, '%s', %d, %d, %d, %d, '%s', %d, %d)", $node->nid, $node->webform['confirmation'], $node->webform['confirmation_format'], $node->webform['redirect_url'], $node->webform['block'], $node->webform['teaser'], $node->webform['allow_draft'], $node->webform['submit_notice'], $node->webform['submit_text'], $node->webform['submit_limit'], $node->webform['submit_interval']);
+
+  // Create the block if enabled.
+  if ($node->webform['block']) {
+    global $theme_key;
+    db_query("INSERT INTO {blocks} (module, delta, theme, cache) VALUES ('%s', %d, '%s', %d)", 'webform', $node->nid, $theme_key, -1);
+  }
 
   // Insert the components into the database. Used with clone.module.
   if (isset($node->webform['components']) && !empty($node->webform['components'])) {
@@ -898,7 +904,17 @@
   }
 
   // Update the webform entry.
-  db_query("UPDATE {webform} SET confirmation = '%s', confirmation_format = %d, redirect_url = '%s', teaser = %d, allow_draft = %d, submit_notice = %d, submit_text = '%s', submit_limit = %d, submit_interval = %d where nid = %d", $node->webform['confirmation'], $node->webform['confirmation_format'], $node->webform['redirect_url'], $node->webform['teaser'], $node->webform['allow_draft'], $node->webform['submit_notice'], $node->webform['submit_text'], $node->webform['submit_limit'], $node->webform['submit_interval'], $node->nid);
+  db_query("UPDATE {webform} SET confirmation = '%s', confirmation_format = %d, redirect_url = '%s', block = %d, teaser = %d, allow_draft = %d, submit_notice = %d, submit_text = '%s', submit_limit = %d, submit_interval = %d where nid = %d", $node->webform['confirmation'], $node->webform['confirmation_format'], $node->webform['redirect_url'], $node->webform['block'], $node->webform['teaser'], $node->webform['allow_draft'], $node->webform['submit_notice'], $node->webform['submit_text'], $node->webform['submit_limit'], $node->webform['submit_interval'], $node->nid);
+
+  // Create the block if enabled.
+  if ($node->webform['block']) {
+    global $theme_key;
+    db_query("REPLACE INTO {blocks} (module, delta, theme, cache) VALUES ('%s', %d, '%s', %d)", 'webform', $node->nid, $theme_key, -1);
+  }
+  // Or delete it if disabled.
+  else {
+    db_query("DELETE FROM {blocks} WHERE module = '%s' AND delta = %d", 'webform', $node->nid); 
+  }
 
   // Compare the webform components and don't do anything if it's not needed.
   $original = node_load($node->nid);
@@ -982,6 +998,7 @@
   db_query('DELETE FROM {webform_roles} WHERE nid = %d', $node->nid);
   db_query('DELETE FROM {webform_submissions} WHERE nid = %d', $node->nid);
   db_query('DELETE FROM {webform_submitted_data} WHERE nid = %d', $node->nid);
+  db_query("DELETE FROM {blocks} WHERE module = '%s' AND delta = %d", 'webform', $node->nid);
 }
 
 /**
@@ -993,6 +1010,7 @@
     'confirmation_format' => FILTER_FORMAT_DEFAULT,
     'redirect_url' => '',
     'teaser' => 0,
+    'block' => 0,
     'allow_draft' => 0,
     'submit_notice' => 0,
     'submit_text' => '',
@@ -1157,12 +1175,14 @@
 
   // Check if the user's role can submit this webform.
   if (variable_get('webform_submission_access_control', 1)) {
-    $allowed_roles = array();
-    foreach ($node->webform['roles'] as $rid) {
-      $allowed_roles[$rid] = isset($user->roles[$rid]) ? TRUE : FALSE;
-    }
-    if (array_search(TRUE, $allowed_roles) === FALSE && $user->uid != 1) {
-      $enabled = FALSE;
+    if (!empty($node->webform['roles'])) {
+      $allowed_roles = array();
+      foreach ($node->webform['roles'] as $rid) {
+        $allowed_roles[$rid] = isset($user->roles[$rid]) ? TRUE : FALSE;
+      }
+      if (array_search(TRUE, $allowed_roles) === FALSE && $user->uid != 1) {
+        $enabled = FALSE;
+      }
     }
   }
   else {
@@ -1326,6 +1346,89 @@
 }
 
 /**
+ * Implementation of hook_block().
+ */
+function webform_block($op = 'list', $delta = 0, $edit = array()) {
+  if ($op == 'list') {
+    $blocks = array();
+    $webform_node_types = webform_variable_get('webform_node_types');
+    if (!empty($webform_node_types)) {
+      $placeholders = db_placeholders($webform_node_types);
+      $result = db_query("SELECT n.title, n.nid FROM {webform} w LEFT JOIN {node} n ON w.nid = n.nid WHERE w.block = 1 AND n.type IN ($placeholders) AND n.status = 1", $webform_node_types);
+      while ($data = db_fetch_object($result)) {
+        $blocks[$data->nid] = array(
+          'info' => t('Webform: @title', array('@title' => $data->title)),
+          'cache' => BLOCK_NO_CACHE,
+        );
+      }
+    }
+    return $blocks;
+  }
+  // The result will be FALSE if this is not a webform node block.
+  $is_webform_block = db_result(db_query("SELECT block FROM {webform} WHERE nid = %d", $delta));
+  if ($is_webform_block) {
+    // Load the settings.
+    $settings = variable_get('webform_blocks', array());
+    $display = isset($settings['block_'. $delta]['display']) ? $settings['block_'. $delta]['display'] : 0;
+    $redirect = isset($settings['block_'. $delta]['redirect']) ? $settings['block_'. $delta]['redirect'] : 0;
+    switch ($op) {
+      case 'view':
+        $node = node_load(array('nid' => $delta));
+        // This is a webform node block.
+        $node->webform_block = TRUE;
+        // Use the node title for the block title, but don't print the title in the block content.
+        $subject = $node->title;
+        if ($redirect == 1) {
+          $node->webform['redirect_url'] = drupal_get_path_alias($_GET['q']);
+        }
+        // Check if the teaser should be displayed in the block.
+        if ($display == 2) {
+          webform_node_view($node, $teaser, FALSE, FALSE);
+          $content = $node->content['webform']['#value'];
+        }
+        else {
+          $teaser = ($display == 1) ? TRUE : FALSE; 
+          $content = node_view($node, $teaser, FALSE, FALSE);
+        }
+        // Create the block.
+        $block = array(
+          'subject' => $subject,
+          'content' => $content,
+        );
+        return $block;
+      case 'configure':
+        // Allow the user to choose if the teaser should be displayed in the block.
+        $form = array();
+        $form['block_'. $delta]['display'] = array(
+          '#type' => 'radios',
+          '#title' => t('Display settings'),
+          '#default_value' => isset($display) ? $display : 0,
+          '#options' => array(t('Full node'), t('Teaser'), t('Form')),
+          '#description' => t('Choose how to display the webform node in the block.'),
+        );
+        $form['block_'. $delta]['redirect'] = array(
+          '#type' => 'radios',
+          '#title' => t('Redirect settings'),
+          '#default_value' => isset($redirect) ? $redirect : 0,
+          '#options' => array(t('Default'), t('To current node')),
+          '#description' => t('Choose where to redirect the user to after successful submission.'),
+        );
+        return $form;
+      case 'save':
+        // Build the settings array.
+        $new_settings['block_'. $delta] = array(
+          'display' => $edit['display'],
+          'redirect' => $edit['redirect']
+        );
+        // We store settings for multiple blocks in just one variable
+        // so we merge the existing settings with the new ones before save.
+        variable_set('webform_blocks', array_merge($settings, $new_settings));
+        break;
+    }
+  }
+}
+
+/**
  * Client form generation function. If this is displaying an existing
  * submission, pass in the $submission variable with the contents of the
  * submission to be displayed.
@@ -1368,7 +1471,7 @@
 
   // Set the form action to the node ID in case this is being displayed on the
   // teaser, subsequent pages should be on the node page directly.
-  if (empty($submission)) {
+  if (!isset($node->webform_block) && empty($submission)) {
     $form['#action'] = url('node/' . $node->nid);
   }
 
@@ -1865,7 +1968,7 @@
     return;
   }
 
-  $node = node_load($form_state['values']['details']['nid']);
+  $node = $form['#node'];
 
   // Check if user is submitting as a draft.
   $is_draft = $form_state['values']['op'] == t('Save Draft');
