diff --git a/core/includes/form.inc b/core/includes/form.inc index 5c0c5cf..2d8d0b5 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -2777,8 +2777,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'; } @@ -2804,23 +2808,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 @@ -2850,9 +2837,6 @@ function theme_form_element_label($variables) { 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 = filter_xss_admin($element['#title']); $attributes = array(); @@ -2869,7 +2853,7 @@ function theme_form_element_label($variables) { $attributes['for'] = $element['#id']; } - return '' . t('!title!required', array('!title' => $title, '!required' => $required)) . ''; + return '' . t('!title', array('!title' => $title)) . ''; } /** diff --git a/core/includes/theme.inc b/core/includes/theme.inc index efd7d23..b33324b 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1938,6 +1938,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'; } @@ -2737,9 +2741,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 %} -

- {% trans %}{{ title|passthrough }}{{ required|passthrough }}{% endtrans %} -

+

{{ title }}

{% endif %} {{ content }} {% if description %} diff --git a/core/modules/field/field.form.inc b/core/modules/field/field.form.inc index c7c2e05..389b760 100644 --- a/core/modules/field/field.form.inc +++ b/core/modules/field/field.form.inc @@ -26,14 +26,12 @@ function theme_field_multiple_value_form($variables) { $output = ''; if ($element['#cardinality_multiple']) { - $form_required_marker = array('#theme' => 'form_required_marker'); - $required = !empty($element['#required']) ? drupal_render($form_required_marker) : ''; $table_id = drupal_html_id($element['#field_name'] . '_values'); $order_class = $element['#field_name'] . '-delta-order'; $header = array( array( - 'data' => '

' . t('!title !required', array('!title' => $element['#title'], '!required' => $required)) . "

", + 'data' => '

' . t('!title', array('!title' => $element['#title'])) . "

", 'colspan' => 2, 'class' => array('field-label'), ), diff --git a/core/modules/system/css/system.theme.css b/core/modules/system/css/system.theme.css index 4e83886..1dd4ba1 100644 --- a/core/modules/system/css/system.theme.css +++ b/core/modules/system/css/system.theme.css @@ -77,13 +77,21 @@ h4.label { .form-type-checkbox .description { margin-left: 2.4em; } -.marker, -.form-required { +.marker { color: #e00; } +.form-required label:after, +.form-required .label:after { + content: "*"; + speak: none; + color: #e00; +} +/* +Not sure how to deal with this... abbr.form-required, abbr.tabledrag-changed, abbr.ajax-changed { border-bottom: none; -} +}*/ + .form-item input.error, .form-item textarea.error, .form-item select.error { diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php index 5424f66..5c864ec 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php @@ -94,7 +94,8 @@ function testRequiredFields() { $elements['file']['empty_values'] = $empty_strings; // Regular expression to find the expected marker on required elements. - $required_marker_preg = '@