diff -urp /home/ben/webform/includes/webform.pages.inc ./includes/webform.pages.inc --- /home/ben/webform/includes/webform.pages.inc 2010-08-18 23:00:45.000000000 -0400 +++ ./includes/webform.pages.inc 2010-08-29 22:09:33.729467240 -0400 @@ -117,6 +117,12 @@ function webform_configure_form(&$form_s '#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'), @@ -181,6 +187,7 @@ function webform_configure_form_validate * Submit handler for webform_configure_form(). */ function webform_configure_form_submit($form, &$form_state) { + global $theme_key; $node = node_load($form_state['values']['nid']); // Save the confirmation. @@ -193,6 +200,18 @@ function webform_configure_form_submit($ // Save roles. $node->webform['roles'] = array_keys(array_filter($form_state['values']['roles'])); + // Set the block option. + $node->webform['block'] = $form_state['values']['block']; + + // Create the block if enabled. + if ($form_state['values']['block']) { + 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); + } + // Set the Show complete form in teaser setting. $node->webform['teaser'] = $form_state['values']['teaser']; Only in ./includes: webform.pages.inc.orig Only in .: webform.6.x-3.x-dev.248157_03.patch Only in .: webform.6.x-3.x-dev.248157_42.patch diff -urp /home/ben/webform/webform.install ./webform.install --- /home/ben/webform/webform.install 2010-08-26 05:33:52.000000000 -0400 +++ ./webform.install 2010-08-29 22:10:07.649683466 -0400 @@ -38,6 +38,13 @@ function webform_schema() { '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', @@ -357,6 +364,7 @@ function webform_uninstall() { 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'; @@ -1182,6 +1190,15 @@ function webform_update_6318() { } /** + * 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. * Only in .: webform.install.orig diff -urp /home/ben/webform/webform.module ./webform.module --- /home/ben/webform/webform.module 2010-08-26 07:56:37.000000000 -0400 +++ ./webform.module 2010-08-29 22:09:33.869552550 -0400 @@ -856,7 +856,7 @@ function webform_node_insert($node) { 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']); // Insert the components into the database. Used with clone.module. if (isset($node->webform['components']) && !empty($node->webform['components'])) { @@ -898,7 +898,7 @@ function webform_node_update($node) { } // 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); // Compare the webform components and don't do anything if it's not needed. $original = node_load($node->nid); @@ -993,6 +993,7 @@ function webform_node_defaults() { 'confirmation_format' => FILTER_FORMAT_DEFAULT, 'redirect_url' => '', 'teaser' => 0, + 'block' => 0, 'allow_draft' => 0, 'submit_notice' => 0, 'submit_text' => '', @@ -1157,12 +1158,14 @@ function webform_node_view(&$node, $teas // 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 +1329,86 @@ function webform_mail($key, &$message, $ } /** + * 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['#tree'] = TRUE; + $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': + // We store settings for multiple blocks in just one variable + // so we merge the existing settings with the new ones before save. + $new_settings['block_'. $delta] = $edit['block_settings']['block_'. $delta]; + 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. @@ -1366,9 +1449,13 @@ function webform_client_form(&$form_stat // Set the encoding type (necessary for file uploads). $form['#attributes']['enctype'] = 'multipart/form-data'; + // Set the form action to the current URL. + if (isset($node->webform_block) && $node->webform_block == TRUE) { + $form['#action'] = url(drupal_get_path_alias($_GET['q'])); + } // 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)) { + elseif (empty($submission)) { $form['#action'] = url('node/' . $node->nid); } @@ -1865,7 +1952,7 @@ function webform_client_form_submit($for 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'); Only in .: webform.module.orig