diff -Naur ../webform.orig/webform.install ./webform.install --- ../webform.orig/webform.install 2008-06-30 08:09:59.000000000 -0700 +++ ./webform.install 2008-08-25 16:16:52.000000000 -0700 @@ -23,6 +23,7 @@ email_subject varchar(255) default NULL, additional_validate text default NULL, additional_submit text default NULL, + block_id int NOT NULL default '-1', PRIMARY KEY (nid) ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */" ); @@ -781,6 +782,13 @@ return $ret; } +function webform_update_5203() { + $query = 'ALTER TABLE {webform} ADD block_id int not null DEFAULT -1'; + $items[] = update_sql($query); + + return $items; +} + /** * Recursively delete all files and folders in the specified filepath, then * delete the containing folder. diff -Naur ../webform.orig/webform.module ./webform.module --- ../webform.orig/webform.module 2008-08-07 17:58:26.000000000 -0700 +++ ./webform.module 2008-08-25 16:16:13.000000000 -0700 @@ -241,6 +241,32 @@ } /** + * Implementation of hook_block() + */ +function webform_block($op = 'list', $delta = 0, $edit = array()) { + if ($op == 'list') { + $blocks = array(); + $query = 'SELECT n.title, n.nid, w.block_id FROM {webform} w INNER JOIN {node} n ON w.nid=n.nid WHERE block_id > -1'; + $resultset = db_query($query); + while ($webform = db_fetch_array($resultset)) { + $blocks[$webform['block_id']]['info'] = $webform['title']; + } + return $blocks; + } + else if ($op == 'view') { + $block = array(); + $block_info = db_fetch_array(db_query('SELECT w.nid, n.title FROM {webform} w INNER JOIN {node} n on w.nid=n.nid WHERE w.block_id=%s', $delta)); + $block['subject'] = $block_info['title']; + $node = node_load($block_info['nid']); + // we show the title as part of the block, so we hide it here + // + $node->title = ''; + $block['content'] = node_view($node, 0, 0); + return $block; + } +} + +/** * Implementation of hook_perm(). */ function webform_perm() { @@ -306,8 +332,15 @@ function webform_insert($node) { include_once(drupal_get_path('module', 'webform') .'/webform_components.inc'); + if ($node->webform['display_as_block'] == 1) { + $node->webform['block_id'] = $node->webform['block_id'] ? $node->webform['block_id'] : db_next_id('{webform}_block_id'); + } + else { + $node->webform['block_id'] = -1; + } + // Insert the Webform. - db_query("INSERT INTO {webform} (nid, confirmation, teaser, submit_text, submit_limit, submit_interval, email, email_from_name, email_from_address, email_subject, additional_validate, additional_submit) VALUES (%d, '%s', %d, '%s', %d, %d, '%s', '%s', '%s', '%s', '%s', '%s')", $node->nid, $node->webform['confirmation'], $node->webform['teaser'], $node->webform['submit_text'], $node->webform['submit_limit'], $node->webform['submit_interval'], $node->webform['email'], $node->webform['email_from_name'], $node->webform['email_from_address'], $node->webform['email_subject'], $node->webform['additional_validate'], $node->webform['additional_submit']); + db_query("INSERT INTO {webform} (nid, confirmation, teaser, submit_text, submit_limit, submit_interval, email, email_from_name, email_from_address, email_subject, additional_validate, additional_submit, block_id) VALUES (%d, '%s', %d, '%s', %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d)", $node->nid, $node->webform['confirmation'], $node->webform['teaser'], $node->webform['submit_text'], $node->webform['submit_limit'], $node->webform['submit_interval'], $node->webform['email'], $node->webform['email_from_name'], $node->webform['email_from_address'], $node->webform['email_subject'], $node->webform['additional_validate'], $node->webform['additional_submit'], $node->webform['block_id']); // Insert the components into the database. Used with clone.module. if (isset($node->webform['components']) && !empty($node->webform['components'])) { @@ -618,6 +651,15 @@ '#weight' => -1, '#parents' => array('webform'), ); + + $form['webform']['advanced']['display_as_block'] = array( + '#type' => 'checkbox', + '#checked_value' => 1, + '#title' => t('Expose as a block'), + '#default_value' => $node->webform['display_as_block'] > -1 ? 1 : 0, + '#description' => t('Check this if you would like to expose this form as a block. It will appear in the blocks configuration page for placement.') + ); + $form['webform']['advanced']['teaser'] = array( '#type' => 'checkbox', '#title' => t('Show complete form in teaser'),