diff --git a/includes/form.inc b/includes/form.inc index e8f1c791047..86fd2c72cf2 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -3042,33 +3042,28 @@ function theme_form_element($variables) { $output = '
' . "\n"; - if (isset($element['#field_prefix'])) { - $output .= '' . $element['#field_prefix'] . ' '; - } + $prefix = isset($element['#field_prefix']) ? '' . $element['#field_prefix'] . ' ' : ''; + $suffix = isset($element['#field_suffix']) ? ' ' . $element['#field_suffix'] . '' : ''; switch ($element['#title_display']) { case 'before': $output .= ' ' . theme('form_element_label', $variables); - $output .= ' ' . $element['#children'] . "\n"; + $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n"; break; case 'invisible': case 'after': - $output .= ' ' . $element['#children']; + $output .= ' ' . $prefix . $element['#children'] . $suffix; $output .= ' ' . theme('form_element_label', $variables) . "\n"; break; case 'none': case 'attribute': // Output no label and no required marker, only the children. - $output .= ' ' . $element['#children'] . "\n"; + $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n"; break; } - if (isset($element['#field_suffix'])) { - $output .= ' ' . $element['#field_suffix'] . ''; - } - if (!empty($element['#description'])) { $output .= '
' . $element['#description'] . "
\n"; } diff --git a/modules/simpletest/tests/form.test b/modules/simpletest/tests/form.test index 40c7490da42..0181dcafb0e 100644 --- a/modules/simpletest/tests/form.test +++ b/modules/simpletest/tests/form.test @@ -375,6 +375,20 @@ class FormsElementsLabelsTestCase extends DrupalWebTestCase { $elements = $this->xpath('//label[@for="edit-form-textfield-test-title-no-show"]'); $this->assertFalse(isset($elements[0]), t("No label tag when title set not to display.")); + + // Check #field_prefix and #field_suffix placement. + $elements = $this->xpath('//span[@class="field-prefix"]/following-sibling::div[@id="edit-form-radios-test"]'); + $this->assertTrue(isset($elements[0]), t("Properly placed the #field_prefix element after the label and before the field.")); + + $elements = $this->xpath('//span[@class="field-suffix"]/preceding-sibling::div[@id="edit-form-radios-test"]'); + $this->assertTrue(isset($elements[0]), t("Properly places the #field_suffix element immediately after the form field.")); + + // Check #prefix and #suffix placement. + $elements = $this->xpath('//div[@id="form-test-textfield-title-prefix"]/following-sibling::div[contains(@class, \'form-item-form-textfield-test-title\')]'); + $this->assertTrue(isset($elements[0]), t("Properly places the #prefix element before the form item.")); + + $elements = $this->xpath('//div[@id="form-test-textfield-title-suffix"]/preceding-sibling::div[contains(@class, \'form-item-form-textfield-test-title\')]'); + $this->assertTrue(isset($elements[0]), t("Properly places the #suffix element before the form item.")); } } diff --git a/modules/simpletest/tests/form_test.module b/modules/simpletest/tests/form_test.module index a8a22abfa0f..94d10faee60 100644 --- a/modules/simpletest/tests/form_test.module +++ b/modules/simpletest/tests/form_test.module @@ -576,6 +576,9 @@ function form_label_test_form() { 'second-radio' => t('Second radio'), 'third-radio' => t('Third radio'), ), + // Test #field_prefix and #field_suffix placement. + '#field_prefix' => '' . t('Radios #field_prefix element') . '', + '#field_suffix' => '' . t('Radios #field_suffix element') . '', ); $form['form_checkbox_test'] = array( '#type' => 'checkbox', @@ -597,6 +600,9 @@ function form_label_test_form() { '#type' => 'textfield', '#title' => t('Textfield test for title only'), // Not required. + // Test #prefix and #suffix placement. + '#prefix' => '
' . t('Textfield #prefix element') . '
', + '#suffix' => '
' . t('Textfield #suffix element') . '
', ); $form['form_textfield_test_title_after'] = array( '#type' => 'textfield',