From 468516d7402a734c155057b08238b9aaf911d4ab Fri, 4 May 2012 20:36:43 +0200 From: hass Date: Fri, 4 May 2012 20:36:08 +0200 Subject: [PATCH] #1114398: theme_form_element() and theme_form_element_label() overrides any custom #attributes diff --git a/includes/form.inc b/includes/form.inc index 3ef32ab..3768f63 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -2804,9 +2804,9 @@ if (isset($element['#id'])) { $attributes['id'] = $element['#id']; } - $attributes['class'] = 'form-radios'; + $attributes['class'] = array('form-radios'); if (!empty($element['#attributes']['class'])) { - $attributes['class'] .= ' ' . implode(' ', $element['#attributes']['class']); + $attributes['class'] = array_merge($attributes['class'], $element['#attributes']['class']); } if (isset($element['#attributes']['title'])) { $attributes['title'] = $element['#attributes']['title']; @@ -3972,8 +3972,8 @@ * @param $variables * An associative array containing: * - element: An associative array containing the properties of the element. - * Properties used: #title, #title_display, #description, #id, #required, - * #children, #type, #name. + * Properties used: #title, #title_display, #title_classes_array, + * #description, #id, #required, #children, #type, #name. * * @ingroup themeable */ @@ -3986,6 +3986,7 @@ // may not necessarily have been processed by form_builder(). $element += array( '#title_display' => 'before', + '#title_classes_array' => array(), ); // Add element #id for #type 'item'. @@ -4004,7 +4005,16 @@ if (!empty($element['#attributes']['disabled'])) { $attributes['class'][] = 'form-disabled'; } + // Add classes specified in the element's #attributes. + if (!empty($element['#attributes']['class'])) { + $attributes['class'] = array_merge($attributes['class'], $element['#attributes']['class']); + } $output = '' . "\n"; + + // Prevent form field class inheriting to label in theme_form_element_label() + // and allow custom label classes. + $variables_title = $variables; + $variables_title['element']['#attributes']['class'] = $element['#title_classes_array']; // If #title is not set, we don't display any label or required marker. if (!isset($element['#title'])) { @@ -4016,13 +4026,13 @@ switch ($element['#title_display']) { case 'before': case 'invisible': - $output .= ' ' . theme('form_element_label', $variables); + $output .= ' ' . theme('form_element_label', $variables_title); $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n"; break; case 'after': $output .= ' ' . $prefix . $element['#children'] . $suffix; - $output .= ' ' . theme('form_element_label', $variables) . "\n"; + $output .= ' ' . theme('form_element_label', $variables_title) . "\n"; break; case 'none': @@ -4098,14 +4108,18 @@ $title = filter_xss_admin($element['#title']); - $attributes = array(); + $attributes = array('class' => array('form-label')); // Style the label as class option to display inline with the element. if ($element['#title_display'] == 'after') { - $attributes['class'] = 'option'; + $attributes['class'][] = 'option'; } // Show label only to screen readers to avoid disruption in visual flows. elseif ($element['#title_display'] == 'invisible') { - $attributes['class'] = 'element-invisible'; + $attributes['class'][] = 'element-invisible'; + } + // Add classes specified in the element's #attributes. + if (!empty($element['#attributes']['class'])) { + $attributes['class'] = array_merge($attributes['class'], $element['#attributes']['class']); } if (!empty($element['#id'])) { diff --git a/modules/field/modules/text/text.js b/modules/field/modules/text/text.js index f3ae894..f42705d 100644 --- a/modules/field/modules/text/text.js +++ b/modules/field/modules/text/text.js @@ -6,7 +6,7 @@ */ Drupal.behaviors.textSummary = { attach: function (context, settings) { - $('.text-summary', context).once('text-summary', function () { + $('.form-item .text-summary', context).once('text-summary', function () { var $widget = $(this).closest('div.field-type-text-with-summary'); var $summaries = $widget.find('div.text-summary-wrapper'); @@ -37,7 +37,7 @@ ).appendTo($summaryLabel); // If no summary is set, hide the summary field. - if ($(this).find('.text-summary').val() == '') { + if ($(this).find('.form-item .text-summary').val() == '') { $link.click(); } return; diff --git a/modules/simpletest/tests/form.test b/modules/simpletest/tests/form.test index 2f5a9cd..fd7cd42 100644 --- a/modules/simpletest/tests/form.test +++ b/modules/simpletest/tests/form.test @@ -587,7 +587,7 @@ */ function testValidateLimitErrors() { $edit = array( - 'test' => 'invalid', + 'test' => 'invalid', 'test_numeric_index[0]' => 'invalid', 'test_substring[foo]' => 'invalid', ); @@ -651,23 +651,23 @@ // Check that the checkbox/radio processing is not interfering with // basic placement. - $elements = $this->xpath('//input[@id="edit-form-checkboxes-test-third-checkbox"]/following-sibling::label[@for="edit-form-checkboxes-test-third-checkbox" and @class="option"]'); + $elements = $this->xpath('//input[@id="edit-form-checkboxes-test-third-checkbox"]/following-sibling::label[@for="edit-form-checkboxes-test-third-checkbox" and contains(@class, "option")]'); $this->assertTrue(isset($elements[0]), t("Label follows field and label option class correct for regular checkboxes.")); // Make sure the label is rendered for checkboxes. - $elements = $this->xpath('//input[@id="edit-form-checkboxes-test-0"]/following-sibling::label[@for="edit-form-checkboxes-test-0" and @class="option"]'); + $elements = $this->xpath('//input[@id="edit-form-checkboxes-test-0"]/following-sibling::label[@for="edit-form-checkboxes-test-0" and contains(@class, "option")]'); $this->assertTrue(isset($elements[0]), t("Label 0 found checkbox.")); - $elements = $this->xpath('//input[@id="edit-form-radios-test-second-radio"]/following-sibling::label[@for="edit-form-radios-test-second-radio" and @class="option"]'); + $elements = $this->xpath('//input[@id="edit-form-radios-test-second-radio"]/following-sibling::label[@for="edit-form-radios-test-second-radio" and contains(@class, "option")]'); $this->assertTrue(isset($elements[0]), t("Label follows field and label option class correct for regular radios.")); // Make sure the label is rendered for radios. - $elements = $this->xpath('//input[@id="edit-form-radios-test-0"]/following-sibling::label[@for="edit-form-radios-test-0" and @class="option"]'); + $elements = $this->xpath('//input[@id="edit-form-radios-test-0"]/following-sibling::label[@for="edit-form-radios-test-0" and contains(@class, "option")]'); $this->assertTrue(isset($elements[0]), t("Label 0 found radios.")); // Exercise various defaults for checkboxes and modifications to ensure // appropriate override and correct behavior. - $elements = $this->xpath('//input[@id="edit-form-checkbox-test"]/following-sibling::label[@for="edit-form-checkbox-test" and @class="option"]'); + $elements = $this->xpath('//input[@id="edit-form-checkbox-test"]/following-sibling::label[@for="edit-form-checkbox-test" and contains(@class, "option")]'); $this->assertTrue(isset($elements[0]), t("Label follows field and label option class correct for a checkbox by default.")); // Exercise various defaults for textboxes and modifications to ensure @@ -678,13 +678,13 @@ $elements = $this->xpath('//input[@id="edit-form-textfield-test-no-title-required"]/preceding-sibling::label[@for="edit-form-textfield-test-no-title-required"]/span[@class="form-required"]'); $this->assertTrue(isset($elements[0]), t("Label tag with required marker precedes required textfield with no title.")); - $elements = $this->xpath('//input[@id="edit-form-textfield-test-title-invisible"]/preceding-sibling::label[@for="edit-form-textfield-test-title-invisible" and @class="element-invisible"]'); + $elements = $this->xpath('//input[@id="edit-form-textfield-test-title-invisible"]/preceding-sibling::label[@for="edit-form-textfield-test-title-invisible" and contains(@class, "element-invisible")]'); $this->assertTrue(isset($elements[0]), t("Label preceding field and label class is element-invisible.")); $elements = $this->xpath('//input[@id="edit-form-textfield-test-title"]/preceding-sibling::span[@class="form-required"]'); $this->assertFalse(isset($elements[0]), t("No required marker on non-required field.")); - $elements = $this->xpath('//input[@id="edit-form-textfield-test-title-after"]/following-sibling::label[@for="edit-form-textfield-test-title-after" and @class="option"]'); + $elements = $this->xpath('//input[@id="edit-form-textfield-test-title-after"]/following-sibling::label[@for="edit-form-textfield-test-title-after" and contains(@class, "option")]'); $this->assertTrue(isset($elements[0]), t("Label after field and label option class correct for text field.")); $elements = $this->xpath('//label[@for="edit-form-textfield-test-title-no-show"]'); diff --git a/modules/user/user-rtl.css b/modules/user/user-rtl.css index 642c943..cdc6df2 100644 --- a/modules/user/user-rtl.css +++ b/modules/user/user-rtl.css @@ -19,7 +19,7 @@ .password-strength-text { float: left; } -div.password-confirm { +div.password-confirm-title { float: left; } .confirm-parent, diff --git a/modules/user/user.css b/modules/user/user.css index 079ec38..70f20aa 100644 --- a/modules/user/user.css +++ b/modules/user/user.css @@ -56,7 +56,7 @@ width: 16em; margin-bottom: 0.4em; } -div.password-confirm { +div.password-confirm-title { float: right; /* LTR */ margin-top: 1.5em; visibility: hidden; diff --git a/modules/user/user.js b/modules/user/user.js index d182066..10f6031 100644 --- a/modules/user/user.js +++ b/modules/user/user.js @@ -16,9 +16,9 @@ innerWrapper.addClass('password-parent'); // Add the password confirmation layer. - $('input.password-confirm', outerWrapper).parent().prepend('
' + translate['confirmTitle'] + '
').addClass('confirm-parent'); + $('input.password-confirm', outerWrapper).parent().prepend('
' + translate['confirmTitle'] + '
').addClass('confirm-parent'); var confirmInput = $('input.password-confirm', outerWrapper); - var confirmResult = $('div.password-confirm', outerWrapper); + var confirmResult = $('div.password-confirm-title', outerWrapper); var confirmChild = $('span', confirmResult); // Add the description box. diff --git a/themes/bartik/css/style.css b/themes/bartik/css/style.css index 4fb8210..08201d9 100644 --- a/themes/bartik/css/style.css +++ b/themes/bartik/css/style.css @@ -1072,13 +1072,13 @@ } .password-strength-text, .password-strength-title, -div.password-confirm { +div.password-confirm-title { font-size: 0.82em; } .password-strength-text { margin-top: 0.2em; } -div.password-confirm { +div.password-confirm-title { margin-top: 2.2em; width: 20.73em; }