From 0885320bb9936b6f6bb28cfa6069099c6832e258 Mon, 8 Jul 2013 21:11:25 +0200
From: hass <hass@85918.no-reply.drupal.org>
Date: Mon, 8 Jul 2013 21:11:11 +0200
Subject: [PATCH] Issue #2033885 by hass: Redirection location inline textfield should not be wrapped in normal form wrappers

diff --git a/includes/webform.emails.inc b/includes/webform.emails.inc
index cfd7cb5..e281be5 100644
--- a/includes/webform.emails.inc
+++ b/includes/webform.emails.inc
@@ -49,8 +49,8 @@
   $form['add']['email_option'] = array(
     '#type' => 'radios',
     '#options' => array(
-      'custom' => t('Address'),
-      'component' => t('Component value'),
+      'custom' => t('Address: !email'),
+      'component' => t('Component value: !component'),
     ),
     '#default_value' => 'custom',
   );
@@ -134,14 +134,16 @@
 
   // Add a default value to the custom e-mail textfield.
   $form['email_custom']['#attributes']['rel'] = t('email@example.com');
-  $form['email_custom']['#attributes']['class'] = array('webform-set-active', 'webform-default-value');
+  $form['email_custom']['#attributes']['class'] = array('webform-default-value');
+  $form['email_custom']['#theme_wrappers'] = array();
+  $form['email_component']['#theme_wrappers'] = array();
+
   $form['email_option']['custom']['#theme_wrappers'] = array('webform_inline_radio');
-  $form['email_option']['custom']['#inline_element'] = drupal_render($form['email_custom']);
+  $form['email_option']['custom']['#title'] = t('Address: !email', array('!email' => drupal_render($form['email_custom'])));
 
   // Render the component value.
-  $form['email_component']['#attributes']['class'] = array('webform-set-active');
   $form['email_option']['component']['#theme_wrappers'] = array('webform_inline_radio');
-  $form['email_option']['component']['#inline_element'] = drupal_render($form['email_component']);
+  $form['email_option']['component']['#title'] = t('Component value: !component', array('!component' => drupal_render($form['email_component'])));
 
   return drupal_render_children($form);
 }
@@ -329,11 +331,12 @@
   // Loop through fields, rendering them into radio button options.
   foreach (array('email', 'subject', 'from_address', 'from_name') as $field) {
     foreach (array('custom', 'component') as $option) {
-      $form[$field . '_' . $option]['#attributes']['class'] = array('webform-set-active');
+      $form[$field . '_' . $option]['#theme_wrappers'] = array();
       $form[$field . '_option'][$option]['#theme_wrappers'] = array('webform_inline_radio');
-      $form[$field . '_option'][$option]['#inline_element'] = drupal_render($form[$field . '_' . $option]);
+      $form[$field . '_option'][$option]['#title'] = t('!title: !field', array('!title' => $form[$field . '_option'][$option]['#title'], '!field' => drupal_render($form[$field . '_' . $option])));
     }
     if (isset($form[$field . '_option']['#options']['default'])) {
+      $form[$field]['#theme_wrappers'] = array();
       $form[$field . '_option']['default']['#theme_wrappers'] = array('webform_inline_radio');
     }
   }
diff --git a/includes/webform.pages.inc b/includes/webform.pages.inc
index 97c9395..27a3586 100644
--- a/includes/webform.pages.inc
+++ b/includes/webform.pages.inc
@@ -71,9 +71,10 @@
     '#default_value' => $redirect,
     '#options' => array(
       'confirmation' => t('Confirmation page'),
-      'url' => t('Custom URL'),
+      'url' => t('Custom URL: !redirect_url'),
       'none' => t('No redirect (reload current page)'),
     ),
+    '#parents' => array('redirect'),
   );
   $form['submission']['redirection']['redirect_url'] = array(
     '#type' => 'textfield',
@@ -81,6 +82,7 @@
     '#description' => t('URL to redirect the user to upon successful submission.'),
     '#default_value' => $redirect_url,
     '#maxlength' => 255,
+    '#parents' => array('redirect_url'),
   );
 
   // Submission limit settings for all submissions.
@@ -354,18 +356,17 @@
  */
 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;
+  // Remove div wrappers around redirect_url field.
+  $form['redirect_url']['#theme_wrappers'] = array();
 
   $form['redirect']['confirmation']['#theme_wrappers'] = array('webform_inline_radio');
+  $form['redirect']['url']['#title'] = t('Custom URL: !redirect_url', array('!redirect_url' => drupal_render($form['redirect_url'])));
   $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);
 }
@@ -375,19 +376,12 @@
  */
 function theme_webform_advanced_submit_limit_form($variables) {
   $form = $variables['form'];
-  $form['submit_limit']['#attributes']['class'] = array('webform-set-active');
-  $form['submit_interval']['#attributes']['class'] = array('webform-set-active');
   // Remove div wrappers around limit options.
   $form['submit_limit']['#theme_wrappers'] = array();
   $form['submit_interval']['#theme_wrappers'] = array();
-  $replacements = array(
-    '!count' => drupal_render($form['submit_limit']),
-    '!timespan' => drupal_render($form['submit_interval']),
-  );
 
   $form['enforce_limit']['no']['#theme_wrappers'] = array('webform_inline_radio');
-  $form['enforce_limit']['yes']['#title'] = NULL;
-  $form['enforce_limit']['yes']['#inline_element'] = t('Limit each user to !count submission(s) !timespan', $replacements);
+  $form['enforce_limit']['yes']['#title'] = t('Limit each user to !count submission(s) !timespan', array('!count' => drupal_render($form['submit_limit']), '!timespan' => drupal_render($form['submit_interval'])));
   $form['enforce_limit']['yes']['#theme_wrappers'] = array('webform_inline_radio');
 
   return drupal_render_children($form);
@@ -398,19 +392,12 @@
  */
 function theme_webform_advanced_total_submit_limit_form($variables) {
   $form = $variables['form'];
-  $form['total_submit_limit']['#attributes']['class'] = array('webform-set-active');
-  $form['total_submit_interval']['#attributes']['class'] = array('webform-set-active');
   // Remove div wrappers around limit options.
   $form['total_submit_limit']['#theme_wrappers'] = array();
   $form['total_submit_interval']['#theme_wrappers'] = array();
-  $replacements = array(
-    '!count' => drupal_render($form['total_submit_limit']),
-    '!timespan' => drupal_render($form['total_submit_interval']),
-  );
 
   $form['enforce_total_limit']['no']['#theme_wrappers'] = array('webform_inline_radio');
-  $form['enforce_total_limit']['yes']['#title'] = NULL;
-  $form['enforce_total_limit']['yes']['#inline_element'] = t('Limit to !count total submission(s) !timespan', $replacements);
+  $form['enforce_total_limit']['yes']['#title'] = t('Limit to !count total submission(s) !timespan', array('!count' => drupal_render($form['total_submit_limit']), '!timespan' => drupal_render($form['total_submit_interval'])));
   $form['enforce_total_limit']['yes']['#theme_wrappers'] = array('webform_inline_radio');
 
   return drupal_render_children($form);
diff --git a/includes/webform.report.inc b/includes/webform.report.inc
index abf8e6d..1f4aeb0 100644
--- a/includes/webform.report.inc
+++ b/includes/webform.report.inc
@@ -585,17 +585,15 @@
   }
 
   // Render latest x submissions option.
-  $element['latest']['#attributes']['class'] = array('webform-set-active');
+  $element['latest']['#theme_wrappers'] = array();
   $element['range_type']['latest']['#theme_wrappers'] = array('webform_inline_radio');
-  $element['range_type']['latest']['#inline_element'] = t('Only the latest !number submissions', array('!number' => drupal_render($element['latest'])));
-  $element['range_type']['latest']['#title'] = NULL;
+  $element['range_type']['latest']['#title'] = t('Only the latest !number submissions', array('!number' => drupal_render($element['latest'])));
 
   // Render Start-End submissions option.
-  $element['start']['#attributes']['class'] = array('webform-set-active');
-  $element['end']['#attributes']['class'] = array('webform-set-active');
+  $element['start']['#theme_wrappers'] = array();
+  $element['end']['#theme_wrappers'] = array();
   $element['range_type']['range']['#theme_wrappers'] = array('webform_inline_radio');
-  $element['range_type']['range']['#inline_element'] = t('All submissions starting from: !start and optionally to: !end', array('!start' => drupal_render($element['start']), '!end' => drupal_render($element['end'])));
-  $element['range_type']['range']['#title'] = NULL;
+  $element['range_type']['range']['#title'] = t('All submissions starting from: !start and optionally to: !end', array('!start' => drupal_render($element['start']), '!end' => drupal_render($element['end'])));
 
   $last_sid = $download_info['sid'] ? $download_info['sid'] : drupal_placeholder(t('none'));
   $element['range_type']['range']['#description'] = '(' . t('Use submission IDs for the range. Last downloaded end SID: !sid.', array('!sid' => $last_sid)) . ')';
diff --git a/js/webform-admin.js b/js/webform-admin.js
index a8e7c9a..9d3874a 100644
--- a/js/webform-admin.js
+++ b/js/webform-admin.js
@@ -8,8 +8,6 @@
 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.
-  Drupal.webform.setActive(context);
   // Update the template select list upon changing a template.
   Drupal.webform.updateTemplate(context);
   // Select all link for file extensions.
@@ -46,14 +44,6 @@
   $forms.submit(function() {
     $fields.focus();
   });
-};
-
-Drupal.webform.setActive = function(context) {
-  var setActive = function(e) {
-    $('.form-radio', $(this).parent().parent()).attr('checked', true);
-    e.preventDefault();
-  };
-  $('.webform-set-active', context).click(setActive).change(setActive);
 };
 
 Drupal.webform.updateTemplate = function(context) {
diff --git a/webform.module b/webform.module
index 6c1fbbd..b40e601 100644
--- a/webform.module
+++ b/webform.module
@@ -538,6 +538,9 @@
     'webform_element' => array(
       'render element' => 'element',
     ),
+    'webform_element_label' => array(
+      'render element' => 'element',
+    ),
     'webform_element_text' => array(
       'render element' => 'element',
     ),
@@ -2754,6 +2757,46 @@
 }
 
 /**
+ * Replacement for theme_form_element_label()
+ *
+ * Custom:
+ * - Allow 'input' tags in '#title' for inline fields.
+ * - Allow 'select' with 'option' tags in '#title' for inline fields.
+ */
+function theme_webform_element_label($variables) {
+  $element = $variables['element'];
+  // This is also used in the installer, pre-database setup.
+  $t = get_t();
+
+  // If title and required marker are both empty, output no label.
+  if ((!isset($element['#title']) || $element['#title'] === '') && empty($element['#required'])) {
+    return '';
+  }
+
+  // If the element is required, a required marker is appended to the label.
+  $required = !empty($element['#required']) ? theme('form_required_marker', array('element' => $element)) : '';
+
+  $title = filter_xss($element['#title'], array('input', 'select', 'option', 'a', 'abbr', 'acronym', 'address', 'article', 'aside', 'b', 'bdi', 'bdo', 'big', 'blockquote', 'br', 'caption', 'cite', 'code', 'col', 'colgroup', 'command', 'dd', 'del', 'details', 'dfn', 'div', 'dl', 'dt', 'em', 'figcaption', 'figure', 'footer', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'header', 'hgroup', 'hr', 'i', 'img', 'ins', 'kbd', 'li', 'mark', 'menu', 'meter', 'nav', 'ol', 'output', 'p', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'section', 'small', 'span', 'strong', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'time', 'tr', 'tt', 'u', 'ul', 'var', 'wbr'));
+
+  $attributes = array();
+  // Style the label as class option to display inline with the element.
+  if ($element['#title_display'] == 'after') {
+    $attributes['class'] = 'option';
+  }
+  // Show label only to screen readers to avoid disruption in visual flows.
+  elseif ($element['#title_display'] == 'invisible') {
+    $attributes['class'] = 'element-invisible';
+  }
+
+  if (!empty($element['#id'])) {
+    $attributes['for'] = $element['#id'];
+  }
+
+  // The leading whitespace helps visually separate fields from inline labels.
+  return ' <label' . drupal_attributes($attributes) . '>' . $t('!title !required', array('!title' => $title, '!required' => $required)) . "</label>\n";
+}
+
+/**
  * Output a form element in plain text format.
  */
 function theme_webform_element_text($variables) {
@@ -2831,17 +2874,11 @@
 
   // Add container-inline to all elements.
   $class[] = 'webform-container-inline';
-  if (isset($element['#inline_element']) && isset($variables['element']['#title'])) {
-    $variables['element']['#title'] .= ': ';
-  }
 
   $output = '<div class="' . implode(' ', $class) . '">' . "\n";
   $output .= ' ' . $element['#children'];
   if (!empty($element['#title'])) {
-    $output .= ' ' . theme('form_element_label', $variables) . "\n";
-  }
-  if (isset($element['#inline_element'])) {
-    $output .= ' ' . $element['#inline_element'] . "\n";
+    $output .= ' ' . theme('webform_element_label', $variables) . "\n";
   }
 
   if (!empty($element['#description'])) {