diff --git a/includes/form.inc b/includes/form.inc index 8f2ee26..feaf629 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -3839,38 +3839,72 @@ function theme_form_element($variables) { if (!empty($element['#attributes']['disabled'])) { $attributes['class'][] = 'form-disabled'; } + + $has_element_children = false; + foreach (array_keys($element) as $key) { + if (substr($key, 0, 1) !== '#') { + $has_element_children = true; + break; + } + } + $output = '' . "\n"; + if ($has_element_children) { + $output .= ' 'fieldset-invisible')) . '>'; + } + // If #title is not set, we don't display any label or required marker. if (!isset($element['#title'])) { $element['#title_display'] = 'none'; } $prefix = isset($element['#field_prefix']) ? '' . $element['#field_prefix'] . ' ' : ''; $suffix = isset($element['#field_suffix']) ? ' ' . $element['#field_suffix'] . '' : ''; + $children = ' ' . $prefix . $element['#children'] . $suffix; + + // Generate the title, either a legend or a label, only if the title will be used + if (!in_array($element['#title_display'], array('none', 'attribute'))) { + if ($has_element_children) { + $attributes = array(); + if ($element['#title_display'] == 'invisible') { + $attributes['class'] = 'element-invisible'; + } + $title = '' . $element['#title']; + if (!empty($element['#required'])) { + $title .= theme('form_required_marker', array('element' => $element)); + } + $title .= ''; + } else { + $title = ' ' . theme('form_element_label', $variables); + } + } switch ($element['#title_display']) { case 'before': case 'invisible': - $output .= ' ' . theme('form_element_label', $variables); - $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n"; + $output .= $title . $children; break; case 'after': - $output .= ' ' . $prefix . $element['#children'] . $suffix; - $output .= ' ' . theme('form_element_label', $variables) . "\n"; + $output .= $children . $title; break; case 'none': case 'attribute': // Output no label and no required marker, only the children. - $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n"; + $output .= $children; break; } + $output .= "\n"; if (!empty($element['#description'])) { $output .= '
' . $element['#description'] . "
\n"; } + if ($has_element_children) { + $output .= ''; + } + $output .= "\n"; return $output; diff --git a/modules/simpletest/tests/form.test b/modules/simpletest/tests/form.test index e7ae9de..10f669b 100644 --- a/modules/simpletest/tests/form.test +++ b/modules/simpletest/tests/form.test @@ -65,7 +65,7 @@ class FormsTestCase extends DrupalWebTestCase { $elements['file']['empty_values'] = $empty_strings; // Regular expression to find the expected marker on required elements. - $required_marker_preg = '@\*@'; + $required_marker_preg = '@<(label|legend).*\*@'; // Go through all the elements and all the empty values for them. foreach ($elements as $type => $data) { diff --git a/modules/system/system.theme.css b/modules/system/system.theme.css index d8dbc51..09a60f3 100644 --- a/modules/system/system.theme.css +++ b/modules/system/system.theme.css @@ -185,6 +185,48 @@ html.js fieldset.collapsed .fieldset-legend { } /** + * Invisible fieldsets. + * + * @see theme_form_element() + */ +fieldset.fieldset-invisible { + margin: 0; + padding: 0; + border: none; + display: inherit; +} +fieldset.fieldset-invisible > legend { + margin: 0; + padding: 0; + border: none; + outline: 0; + font-style: inherit; + font-size: 100%; + font-family: inherit; + vertical-align: baseline; + + border-radius: 0; + color: inherit; + background-color: transparent; + background-image: none; + + display: block; + font-weight: bold; + + position: static; + left: 0; + right: 0; + top: 0; + bottom: 0; + + text-indent: 0; + text-shadow: none; + line-height: normal; + width: auto; + height: auto; +} + +/** * TableDrag behavior. * * @see tabledrag.js