diff --git a/core/includes/form.inc b/core/includes/form.inc index ce5779c..820f146 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -2767,8 +2767,12 @@ function template_preprocess_form_element(&$variables) { if (!empty($element['#attributes']['disabled'])) { $variables['attributes']['class'][] = 'form-disabled'; } + // Add a class for required elements. + if (!empty($element['#required'])) { + $variables['attributes']['class'][] = 'form-required'; + } - // If #title is not set, we don't display any label or required marker. + // If #title is not set, we don't display any label. if (!isset($element['#title'])) { $element['#title_display'] = 'none'; } @@ -2794,23 +2798,6 @@ function template_preprocess_form_element(&$variables) { } /** - * Returns HTML for a marker for required form elements. - * - * @param $variables - * An associative array containing: - * - element: An associative array containing the properties of the element. - * - * @ingroup themeable - */ -function theme_form_required_marker($variables) { - $attributes = array( - 'class' => 'form-required', - 'aria-hidden' => 'true', - ); - return '*'; -} - -/** * Returns HTML for a form element label and required marker. * * Form element labels include the #title and a #required marker. The label is @@ -2840,16 +2827,6 @@ function theme_form_element_label($variables) { return ''; } - // If the element is required, a required marker is appended to the label. - $required = ''; - if (!empty($element['#required'])) { - $marker = array( - '#theme' => 'form_required_marker', - '#element' => $element, - ); - $required = drupal_render($marker); - } - $title = filter_xss_admin($element['#title']); $attributes = array(); @@ -2866,7 +2843,7 @@ function theme_form_element_label($variables) { $attributes['for'] = $element['#id']; } - return ''; + return ''; } /** diff --git a/core/includes/theme.inc b/core/includes/theme.inc index f98aadd..0ab996d 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1898,6 +1898,10 @@ function theme_container($variables) { if (!isset($element['#attributes']['id'])) { $element['#attributes']['id'] = $element['#id']; } + // Add a class for required elements. + if (!empty($element['widget']['#required'])) { + $element['#attributes']['class'][] = 'form-required'; + } // Add the 'form-wrapper' class. $element['#attributes']['class'][] = 'form-wrapper'; } @@ -2700,9 +2704,6 @@ function drupal_common_theme() { 'render element' => 'element', 'template' => 'form-element', ), - 'form_required_marker' => array( - 'render element' => 'element', - ), 'form_element_label' => array( 'render element' => 'element', ), diff --git a/core/misc/states.js b/core/misc/states.js index abdfbf8..4e57f95 100644 --- a/core/misc/states.js +++ b/core/misc/states.js @@ -517,14 +517,14 @@ $(document).on('state:required', function (e) { if (e.trigger) { if (e.value) { - var $label = $(e.target).attr({ 'required': 'required', 'aria-required': 'aria-required' }).closest('.form-item, .form-wrapper').find('label'); + var $formWrapper = $(e.target).attr({ 'required': 'required', 'aria-required': 'aria-required' }).closest('.form-item, .form-wrapper'); // Avoids duplicate required markers on initialization. - if (!$label.find('.form-required').length) { - $label.append(Drupal.theme('requiredMarker')); + if (!$formWrapper.hasClass('form-required').length) { + $formWrapper.addClass('form-required'); } } else { - $(e.target).removeAttr('required aria-required').closest('.form-item, .form-wrapper').find('label .form-required').remove(); + $(e.target).removeAttr('required aria-required').closest('.form-item.form-required, .form-wrapper.form-required').removeClass('form-required'); } } }); @@ -570,10 +570,4 @@ return (a === b) ? (typeof a === 'undefined' ? a : true) : (typeof a === 'undefined' || typeof b === 'undefined'); } - $.extend(Drupal.theme, { - requiredMarker: function () { - return '*'; - } - }); - })(jQuery); diff --git a/core/modules/datetime/datetime.module b/core/modules/datetime/datetime.module index ccf1a0c..8828f85 100644 --- a/core/modules/datetime/datetime.module +++ b/core/modules/datetime/datetime.module @@ -224,16 +224,6 @@ function template_preprocess_datetime_form(&$variables) { */ function template_preprocess_datetime_wrapper(&$variables) { $element = $variables['element']; - - // If the element is required, a required marker is appended to the label. - $variables['required'] = NULL; - if(!empty($element['#required'])) { - $variables['required'] = array( - '#theme' => 'form_required_marker', - '#element' => $element, - ); - } - if (!empty($element['#title'])) { $variables['title'] = $element['#title']; } diff --git a/core/modules/datetime/templates/datetime-wrapper.html.twig b/core/modules/datetime/templates/datetime-wrapper.html.twig index a4acf70..cb73680 100644 --- a/core/modules/datetime/templates/datetime-wrapper.html.twig +++ b/core/modules/datetime/templates/datetime-wrapper.html.twig @@ -7,7 +7,6 @@ * - content: The form element to be output, usually a datelist, or datetime. * - title: The title of the form element. * - attributes: HTML attributes for the form wrapper. - * - required: (optional) A marker indicating that the form element is required. * - description: Description text for the form element. * * @see template_preprocess_datetime_wrapper() @@ -16,9 +15,7 @@ */ #} {% if title %} -