- Patch #755030 by jhedstrom, sivaji, kkaefer: #field_prefix()/suffix is displayed before the label. With tests.
parent
680dae6e78
commit
7745a082d0
|
@ -3042,33 +3042,28 @@ function theme_form_element($variables) {
|
|||
|
||||
$output = '<div class="' . implode(' ', $class) . '">' . "\n";
|
||||
|
||||
if (isset($element['#field_prefix'])) {
|
||||
$output .= '<span class="field-prefix">' . $element['#field_prefix'] . '</span> ';
|
||||
}
|
||||
$prefix = isset($element['#field_prefix']) ? '<span class="field-prefix">' . $element['#field_prefix'] . '</span> ' : '';
|
||||
$suffix = isset($element['#field_suffix']) ? ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>' : '';
|
||||
|
||||
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 .= ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>';
|
||||
}
|
||||
|
||||
if (!empty($element['#description'])) {
|
||||
$output .= ' <div class="description">' . $element['#description'] . "</div>\n";
|
||||
}
|
||||
|
|
|
@ -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."));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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' => '<span id="form-test-radios-field-prefix">' . t('Radios #field_prefix element') . '</span>',
|
||||
'#field_suffix' => '<span id="form-test-radios-field-suffix">' . t('Radios #field_suffix element') . '</span>',
|
||||
);
|
||||
$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' => '<div id="form-test-textfield-title-prefix">' . t('Textfield #prefix element') . '</div>',
|
||||
'#suffix' => '<div id="form-test-textfield-title-suffix">' . t('Textfield #suffix element') . '</div>',
|
||||
);
|
||||
$form['form_textfield_test_title_after'] = array(
|
||||
'#type' => 'textfield',
|
||||
|
|
Loading…
Reference in New Issue