diff -u includes/form.inc includes/form.inc --- includes/form.inc 1 Dec 2009 17:12:02 -0000 +++ includes/form.inc 2 Dec 2009 01:55:53 -0000 @@ -2832,38 +2832,37 @@ /** * Theme a form element. * - * Each form element is wrapped in a div with #type and #name classes. In + * Each form element is wrapped in a DIV with #type and #name classes. In * addition to the element itself, the div contains a label before or after * the element based on the optional #title_display property. After the label * and fields this function outputs the optional element #description. * * The optional #title_display property can have these values: * - before: The label is output before the element. This is the default. - * The label includes the #title and the required marker, if #required. + * The label includes the #title and the required marker, if #required. * - after: The label is output after the element. For example, this is used - * for radio and checkbox #type elements as set in system_element_info(). - * If the #title is empty but the field is #required, the label will - * contain only the required marker. + * for radio and checkbox #type elements as set in system_element_info(). + * If the #title is empty but the field is #required, the label will + * contain only the required marker. * - attribute: Set the title attribute on the element to create a tooltip - * but output no label element. This is supported only for checkboxes - * and radios in form_pre_render_conditional_form_element(). It is used - * where a visual label is not needed, such as a table of checkboxes where - * the row and column provide the context. The tooltip will include the - * title and required marker. - * The label or attribute includes a required marker for required fields. - * - * If the #title property is not set the label and any required marker will - * not be displayed. This is used by the password_confirm element #type. - * The password_confirm field creates children elements that have their own - * labels and required markers, but the parent element should have neither. - * Use this carefully because a field with no label and no surrounding context - * causes challenges for accessibility. + * but output no label element. This is supported only for checkboxes + * and radios in form_pre_render_conditional_form_element(). It is used + * where a visual label is not needed, such as a table of checkboxes where + * the row and column provide the context. The tooltip will include the + * title and required marker. + * + * If the #title property is not set, then the label and any required marker + * will not be output, regardless of the #title_display or #required values. + * This can be useful in cases such as the password_confirm element, which + * creates children elements that have their own labels and required markers, + * but the parent element should have neither. Use this carefully because a + * field without an associated label can cause accessibility challenges. * * @param $variables * An associative array containing: * - element: An associative array containing the properties of the element. - * Properties used: #title, #description, #id, #required, #children, #type, - * #name, #title_display. + * Properties used: #title, #title_display, #description, #id, #required, + * #children, #type, #name. * * @return * A string representing the form element. @@ -2884,9 +2883,9 @@ $class[] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => '')); } - - // If #title is not present, we don't display any label or required marker + + // If #title is not set, we don't display any label or required marker. if (!isset($element['#title'])) { - $element['#title_display'] = 'none'; + $element['#title_display'] = 'none'; } $output = '
' . "\n"; @@ -2926,20 +2925,13 @@ * An associative array containing: * - element: An associative array containing the properties of the element. * @return - * A string representing the marker to identify required form elements, - * or an empty string for non-required elements. + * A string representing the marker to identify required form elements. * * @ingroup themeable */ function theme_form_required_marker($variables) { // This is also used in the installer, pre-database setup. $t = get_t(); - - if (empty($variables['element']['#required'])) { - // If this element is not required, it gets no required marker. - return ''; - } - $attributes = array( 'class' => 'form-required', 'title' => $t('This field is required.'), @@ -2975,20 +2967,15 @@ // This is also used in the installer, pre-database setup. $t = get_t(); - // If the element is required, append a required marker to the label. - // If the element is not required, skip the unnecessary funtion call. + // If title and required marker are both empty, output no label. + if (empty($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 = ''; - if (empty($element['#title'])) { - if (empty($required)) { - // If title and required marker are both empty, output no label. - return ''; - } - } - else { - $title = filter_xss_admin($element['#title']); - } + $title = filter_xss_admin($element['#title']); $attributes = array(); if ($element['#title_display'] == 'after') { @@ -2999,6 +2986,7 @@ $attributes['for'] = $element['#id']; } + // The leading whitespace helps visually separate fields from inline labels. return ' ' . $t('!title !required', array('!title' => $title, '!required' => $required)) . "\n"; }