diff --git a/core/includes/form.inc b/core/includes/form.inc index 19993c6..0c7119f 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -1824,6 +1824,7 @@ function form_builder($form_id, &$element, &$form_state) { '#required' => FALSE, '#attributes' => array(), '#title_display' => 'before', + '#description_position' => 'after', ); // Special handling if we're on the top level form element. @@ -4623,7 +4624,9 @@ function form_pre_render_file($element) { * - form-disabled: Only set if the form element is #disabled. * * In addition to the element itself, the DIV contains a label for the element - * based on the optional #title_display property, and an optional #description. + * based on the optional #title_display property, and an optional #description, + * that can be output before or after the field depending on the + * #description_position property. * * The optional #title_display property can have these values: * - before: The label is output before the element. This is the default. @@ -4649,11 +4652,19 @@ function form_pre_render_file($element) { * but the parent element should have neither. Use this carefully because a * field without an associated label can cause accessibility challenges. * + * The optional #description_position property can have these values: + * - before: The description is output before the element. + * - after: The description is output after the element. + * + * If the #description property is not set, the description will not be output, + * regardless of the #description_position value. + * The default value of #description_position is 'after'. + * * @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, #description, #description_position, + * #id, #required, #children, #type, #name. * * @ingroup themeable */ @@ -4664,6 +4675,7 @@ function theme_form_element($variables) { // may not necessarily have been processed by form_builder(). $element += array( '#title_display' => 'before', + '#description_position' => 'after', ); // Take over any #wrapper_attributes defined by the element. @@ -4701,10 +4713,16 @@ function theme_form_element($variables) { case 'before': case 'invisible': $output .= ' ' . theme('form_element_label', $variables); + if (!empty($element['#description']) && $element['#description_position'] == 'before') { + $output .= '
' . $element['#description'] . "
\n"; + } $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n"; break; case 'after': + if (!empty($element['#description']) && $element['#description_position'] == 'before') { + $output .= '
' . $element['#description'] . "
\n"; + } $output .= ' ' . $prefix . $element['#children'] . $suffix; $output .= ' ' . theme('form_element_label', $variables) . "\n"; break; @@ -4715,8 +4733,7 @@ function theme_form_element($variables) { $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n"; break; } - - if (!empty($element['#description'])) { + if (!empty($element['#description']) && $element['#description_position'] == 'after') { $attributes = array('class' => 'description'); if (!empty($element['#id'])) { $attributes['id'] = $element['#id'] . '--description'; diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 8ddbf09..5ff3b41 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -287,6 +287,8 @@ function hook_queue_info_alter(&$queues) { * - "#submit": array of callback functions taking $form and $form_state. * - "#title_display": optional string indicating if and how #title should be * displayed, see theme_form_element() and theme_form_element_label(). + * - "#description_position": optional string indicating how the #description should + * be displayed, see theme_form_element(). * * @see hook_element_info_alter() * @see system_element_info()