Index: css/webform-admin.css
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/css/webform-admin.css,v
retrieving revision 1.4
diff -u -r1.4 webform-admin.css
--- css/webform-admin.css 28 Sep 2010 20:49:21 -0000 1.4
+++ css/webform-admin.css 17 Oct 2010 18:41:37 -0000
@@ -64,7 +64,8 @@
text-align: center;
width: 40px;
}
-.webform-container-inline div {
+.webform-container-inline div,
+.webform-container-inline div.form-item {
display: inline;
}
.webform-default-value {
Index: css/webform.css
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/css/webform.css,v
retrieving revision 1.3
diff -u -r1.3 webform.css
--- css/webform.css 19 Aug 2010 03:00:42 -0000 1.3
+++ css/webform.css 17 Oct 2010 18:41:37 -0000
@@ -8,6 +8,7 @@
padding: 3px;
vertical-align: top;
}
-.webform-container-inline div {
+.webform-container-inline div,
+.webform-container-inline div.form-item {
display: inline;
}
Index: includes/webform.pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/includes/webform.pages.inc,v
retrieving revision 1.17
diff -u -r1.17 webform.pages.inc
--- includes/webform.pages.inc 19 Aug 2010 03:00:42 -0000 1.17
+++ includes/webform.pages.inc 17 Oct 2010 18:41:37 -0000
@@ -36,7 +36,7 @@
$form['submission']['confirmation'] = array(
'#type' => 'text_format',
'#title' => t('Confirmation message'),
- '#description' => t('Message to be shown upon successful submission. If Redirect URL is set this displays as a message, otherwise it will be shown on its own page.'),
+ '#description' => t('Message to be shown upon successful submission. If the redirection location is set to Confirmation page it will be shown on its own page, otherwise this displays as a message.'),
'#default_value' => $node->webform['confirmation'],
'#cols' => 40,
'#rows' => 10,
@@ -44,12 +44,42 @@
'#parents' => array('confirmation'),
);
- // Redirect URL.
- $form['submission']['redirect_url'] = array(
+ // Redirection settings.
+ if (strpos($node->webform['redirect_url'], '<') === 0) {
+ $redirect = trim($node->webform['redirect_url'], '<>');
+ // Redirection is set to front page.
+ if ($redirect == 'front') {
+ $redirect = 'url';
+ $redirect_url = $node->webform['redirect_url'];
+ }
+ else {
+ $redirect_url = '';
+ }
+ }
+ else {
+ $redirect = 'url';
+ $redirect_url = $node->webform['redirect_url'];
+ }
+ $form['submission']['redirection'] = array(
+ '#type' => 'item',
+ '#title' => t('Redirection location'),
+ '#theme' => 'webform_advanced_redirection_form',
+ '#description' => t('Choose where to redirect the user upon successful submission.'),
+ );
+ $form['submission']['redirection']['redirect']= array(
+ '#type' => 'radios',
+ '#default_value' => $redirect,
+ '#options' => array(
+ 'confirmation' => t('Confirmation page'),
+ 'url' => t('Custom URL'),
+ 'none' => t('No redirect (reload current page)'),
+ ),
+ );
+ $form['submission']['redirection']['redirect_url'] = array(
'#type' => 'textfield',
'#title' => t('Redirect URL'),
'#description' => t('URL to redirect the user to upon successful submission.'),
- '#default_value' => $node->webform['redirect_url'],
+ '#default_value' => $redirect_url,
'#maxlength' => 255,
);
@@ -121,6 +151,13 @@
'#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 will be available as a block.'),
+ '#access' => user_access('administer blocks') || user_access('administer site configuration') || user_access('use panels dashboard'),
+ );
$form['advanced']['teaser'] = array(
'#type' => 'checkbox',
'#title' => t('Show complete form in teaser'),
@@ -172,12 +209,23 @@
}
// Ensure the entered redirect URL is valid.
- $redirect_url = trim($form_state['values']['redirect_url']);
- if (!empty($redirect_url) && strpos($redirect_url, 'http') === 0 && !valid_url($redirect_url, TRUE)) {
- form_error($form['submission']['redirect_url'], t('The entered URL is not a valid address.'));
+ if ($form_state['values']['redirect'] == 'url') {
+ $redirect_url = trim($form_state['values']['redirect_url']);
+ if (empty($redirect_url)) {
+ form_error($form['submission']['redirection']['redirect_url'], t('A valid URL is required for custom redirection.'));
+ }
+ elseif (strpos($redirect_url, 'http') === 0 && !valid_url($redirect_url, TRUE)) {
+ form_error($form['submission']['redirection']['redirect_url'], t('The entered URL is not a valid address.'));
+ }
+ else {
+ form_set_value($form['submission']['redirection']['redirect_url'], $redirect_url, $form_state);
+ }
+ }
+ elseif ($form_state['values']['redirect'] == 'confirmation') {
+ form_set_value($form['submission']['redirection']['redirect_url'], '', $form_state);
}
else {
- form_set_value($form['submission']['redirect_url'], $redirect_url, $form_state);
+ form_set_value($form['submission']['redirection']['redirect_url'], '', $form_state);
}
}
@@ -197,6 +245,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'];
@@ -225,6 +276,27 @@
}
/**
+ * Theme the redirection setting on the webform node form.
+ */
+function theme_webform_advanced_redirection_form($variables) {
+ $form = $variables['form'];
+ // Add special class for setting the active radio button.
+ $form['redirect_url']['#attributes']['class'] = array('webform-set-active');
+
+ // Remove title and description for Redirect URL field.
+ $form['redirect_url']['#title'] = NULL;
+ $form['redirect_url']['#description'] = NULL;
+
+ $form['redirect']['confirmation']['#theme_wrappers'] = array('webform_inline_radio');
+ $form['redirect']['url']['#theme_wrappers'] = array('webform_inline_radio');
+ $form['redirect']['none']['#theme_wrappers'] = array('webform_inline_radio');
+ $form['redirect']['url']['#inline_element'] = $form['redirect']['url']['#title'] . ': ' . drupal_render($form['redirect_url']);
+ $form['redirect']['url']['#title'] = NULL;
+
+ return drupal_render_children($form);
+}
+
+/**
* Theme the submit limit fieldset on the webform node form.
*/
function theme_webform_advanced_submit_limit_form($variables) {
Index: js/webform-admin.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/js/webform-admin.js,v
retrieving revision 1.5
diff -u -r1.5 webform-admin.js
--- js/webform-admin.js 4 Sep 2010 18:14:05 -0000 1.5
+++ js/webform-admin.js 17 Oct 2010 18:41:37 -0000
@@ -5,8 +5,8 @@
* Webform node form interface enhancments.
*/
-Drupal.behaviors.webform = {};
-Drupal.behaviors.webform.attach = function(context) {
+Drupal.behaviors.webformAdmin = {};
+Drupal.behaviors.webformAdmin.attach = function(context) {
// Apply special behaviors to fields with default values.
Drupal.webform.defaultValues(context);
// On click or change, make a parent radio button selected.
Index: webform.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.install,v
retrieving revision 1.57
diff -u -r1.57 webform.install
--- webform.install 17 Oct 2010 02:28:56 -0000 1.57
+++ webform.install 17 Oct 2010 18:41:36 -0000
@@ -37,6 +37,14 @@
'description' => 'The URL a user is redirected to after submitting a form.',
'type' => 'varchar',
'length' => 255,
+ 'default' => '',
+ ),
+ '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.',
@@ -377,6 +385,7 @@
variable_del('webform_default_format');
variable_del('webform_format_override');
variable_del('webform_csv_delimiter');
+ variable_del('webform_blocks');
$component_list = array();
$path = drupal_get_path('module', 'webform') . '/components';
@@ -424,3 +433,15 @@
function webform_update_7303() {
db_change_field('webform', 'submit_notice', 'submit_notice', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 1));
}
+
+/**
+ * Add field for block feature and redirection setting.
+ */
+function webform_update_7304() {
+ db_add_field('webform', 'block', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0));
+ db_change_field('webform', 'redirect_url', 'redirect_url', array('type' => 'varchar', 'length' => 255, 'default' => ''));
+ db_update('webform')
+ ->fields(array('redirect_url' => 'confirmation'))
+ ->condition('redirect_url', '')
+ ->execute();
+}
Index: webform.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.module,v
retrieving revision 1.260
diff -u -r1.260 webform.module
--- webform.module 17 Oct 2010 02:28:56 -0000 1.260
+++ webform.module 17 Oct 2010 18:41:37 -0000
@@ -517,10 +517,6 @@
'template' => 'templates/webform-form',
'pattern' => 'webform_form_[0-9]+',
),
- 'webform_advanced_submit_limit_form' => array(
- 'render element' => 'form',
- 'file' => 'includes/webform.pages.inc',
- ),
'webform_confirmation' => array(
'variables' => array('node' => NULL, 'sid' => NULL),
'template' => 'templates/webform-confirmation',
@@ -582,6 +578,15 @@
'render element' => 'element',
'file' => 'includes/webform.components.inc',
),
+ // webform.pages.inc.
+ 'webform_advanced_redirection_form' => array(
+ 'render element' => 'form',
+ 'file' => 'includes/webform.pages.inc',
+ ),
+ 'webform_advanced_submit_limit_form' => array(
+ 'render element' => 'form',
+ 'file' => 'includes/webform.pages.inc',
+ ),
// webform.report.inc.
'webform_results_per_page' => array(
'variables' => array('total_count' => NULL, 'pager_count' => NULL),
@@ -877,20 +882,8 @@
module_load_include('inc', 'webform', 'includes/webform.emails');
// Insert the webform.
- db_insert('webform')
- ->fields(array(
- 'nid' => $node->nid,
- 'confirmation' => $node->webform['confirmation'],
- 'confirmation_format' => $node->webform['confirmation_format'],
- 'redirect_url' => $node->webform['redirect_url'],
- 'teaser' => $node->webform['teaser'],
- 'allow_draft' => $node->webform['allow_draft'],
- 'submit_notice' => $node->webform['submit_notice'],
- 'submit_text' => $node->webform['submit_text'],
- 'submit_limit' => $node->webform['submit_limit'],
- 'submit_interval' => $node->webform['submit_interval'],
- ))
- ->execute();
+ $node->webform['nid'] = $node->nid;
+ drupal_write_record('webform', $node->webform);
// Insert the components into the database. Used with clone.module.
if (isset($node->webform['components']) && !empty($node->webform['components'])) {
@@ -923,20 +916,8 @@
}
// Update the webform entry.
- db_merge('webform')
- ->fields(array(
- 'confirmation' => $node->webform['confirmation'],
- 'confirmation_format' => $node->webform['confirmation_format'],
- 'redirect_url' => $node->webform['redirect_url'],
- 'teaser' => $node->webform['teaser'],
- 'allow_draft' => $node->webform['allow_draft'],
- 'submit_notice' => $node->webform['submit_notice'],
- 'submit_text' => $node->webform['submit_text'],
- 'submit_limit' => $node->webform['submit_limit'],
- 'submit_interval' => $node->webform['submit_interval'],
- ))
- ->key(array('nid' => $node->nid))
- ->execute();
+ $node->webform['nid'] = $node->nid;
+ drupal_write_record('webform', $node->webform, array('nid'));
// Compare the webform components and don't do anything if it's not needed.
$original = node_load($node->nid);
@@ -1029,8 +1010,9 @@
return array(
'confirmation' => '',
'confirmation_format' => filter_default_format(),
- 'redirect_url' => '',
+ 'redirect_url' => '',
'teaser' => 0,
+ 'block' => 0,
'allow_draft' => 0,
'submit_notice' => 1,
'submit_text' => '',
@@ -1212,6 +1194,7 @@
return;
}
+ $info = array();
$submission = array();
$submission_count = 0;
$enabled = TRUE;
@@ -1277,7 +1260,7 @@
}
// Print out messages for the webform.
- if (empty($node->in_preview) && !$logging_in) {
+ if (empty($node->in_preview) && !isset($node->webform_block) && !$logging_in) {
theme('webform_view_messages', array('node' => $node, 'teaser' => $teaser, 'page' => $page, 'submission_count' => $submission_count, 'limit_exceeded' => $limit_exceeded, 'allowed_roles' => $allowed_roles));
}
@@ -1408,6 +1391,125 @@
}
/**
+ * Implementation of hook_block_info().
+ */
+function webform_block_info() {
+ $blocks = array();
+ $webform_node_types = webform_variable_get('webform_node_types');
+ if (!empty($webform_node_types)) {
+ $query = db_select('webform', 'w')->fields('w')->fields('n', array('title'));
+ $query->leftJoin('node', 'n', 'w.nid = n.nid');
+ $query->condition('w.block', 1);
+ $query->condition('n.type', $webform_node_types, 'IN');
+ $result = $query->execute();
+ foreach ($result as $data) {
+ $blocks['client-block-'. $data->nid] = array(
+ 'info' => t('Webform: !title', array('!title' => $data->title)),
+ 'cache' => DRUPAL_NO_CACHE,
+ );
+ }
+ }
+ return $blocks;
+}
+
+/**
+ * Implementation of hook_block_view().
+ */
+function webform_block_view($delta = '') {
+ global $user;
+
+ // Load the block-specific configuration settings.
+ $webform_blocks = variable_get('webform_blocks', array());
+ $settings = isset($webform_blocks[$delta]) ? $webform_blocks[$delta] : array();
+ $settings += array(
+ 'display' => 'form',
+ );
+
+ // Get the node ID from delta.
+ $nid = drupal_substr($delta, strrpos($delta, '-') + 1);
+
+ // Load node in current language.
+ if (module_exists('translation')) {
+ global $language;
+ if (($translations = translation_node_get_translations($nid)) && (isset($translations[$language->language]))) {
+ $nid = $translations[$language->language]->nid;
+ }
+ }
+
+ // The webform node to display in the block.
+ $node = node_load($nid);
+
+ // Return if user has no access to the webform node.
+ if (!node_access('view', $node)) {
+ return;
+ }
+
+ // This is a webform node block.
+ $node->webform_block = TRUE;
+
+ // Use the node title for the block title.
+ $subject = $node->title;
+
+ // Generate the content of the block based on display settings.
+ if ($settings['display'] == 'form') {
+ webform_node_view($node, 'full');
+ $content = $node->content['webform'];
+ }
+ else {
+ $teaser = ($settings['display'] == 'teaser') ? 'teaser' : 'full';
+ $content = node_view($node, $teaser);
+ }
+
+ // Create the block.
+ $block = array(
+ 'subject' => $subject,
+ 'content' => $content,
+ );
+ return $block;
+}
+
+/**
+ * Implementation of hook_block_configure().
+ */
+function webform_block_configure($delta = '') {
+ // Load the block-specific configuration settings.
+ $webform_blocks = variable_get('webform_blocks', array());
+ $settings = isset($webform_blocks[$delta]) ? $webform_blocks[$delta] : array();
+ $settings += array(
+ 'display' => 'form',
+ );
+
+ $form = array();
+ $form['display'] = array(
+ '#type' => 'radios',
+ '#title' => t('Display mode'),
+ '#default_value' => $settings['display'],
+ '#options' => array(
+ 'form' => t('Form only'),
+ 'full' => t('Full node'),
+ 'teaser' => t('Teaser'),
+ ),
+ '#description' => t('The display mode determines how much of the webform to show within the block.'),
+ );
+ return $form;
+}
+
+/**
+ * Implementation of hook_block_save().
+ */
+function webform_block_save($delta = '', $edit = array()) {
+ // Load the previously defined block-specific configuration settings.
+ $settings = variable_get('webform_blocks', array());
+ // Build the settings array.
+ $new_settings[$delta] = array(
+ 'display' => $edit['display'],
+ );
+ // 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));
+}
+
+/**
* 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.
@@ -1455,7 +1557,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);
}
@@ -1951,7 +2053,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');
@@ -2121,35 +2223,37 @@
// Check confirmation and redirect_url fields.
$message = NULL;
+ $redirect = NULL;
$external_url = FALSE;
if ($is_draft) {
- $redirect = NULL;
$message = t('Draft saved');
}
elseif (!empty($form_state['values']['details']['finished'])) {
- $redirect = NULL;
$message = t('Submission updated.');
}
+ elseif ($redirect_url == '') {
+ $redirect = NULL;
+ }
+ elseif ($redirect_url == '') {
+ $redirect = array('node/' . $node->nid . '/done', array('query' => array('sid' => $sid)));
+ }
elseif (valid_url($redirect_url, TRUE)) {
$redirect = $redirect_url;
$external_url = TRUE;
- }
+ }
elseif ($redirect_url && strpos($redirect_url, 'http') !== 0) {
$parts = drupal_parse_url($redirect_url);
$parts['query'] ? ($parts['query']['sid'] = $sid) : ($parts['query'] = array('sid' => $sid));
$query = $parts['query'];
$redirect = array($parts['path'], array('query' => $query, 'fragment' => $parts['fragment']));
}
- else {
- $redirect = array('node/' . $node->nid . '/done', array('query' => array('sid' => $sid)));
- }
// Show a message if manually set.
if (isset($message)) {
drupal_set_message($message);
}
// If redirecting and we have a confirmation message, show it as a message.
- elseif (!$external_url && !empty($redirect_url) && !empty($confirmation)) {
+ elseif (!$external_url && (!empty($redirect_url) && $redirect_url != '') && !empty($confirmation)) {
drupal_set_message(check_markup($confirmation, $node->webform['confirmation_format'], FALSE));
}