diff --git a/core/modules/datetime/datetime.module b/core/modules/datetime/datetime.module index 3a016b5..f12ee12 100644 --- a/core/modules/datetime/datetime.module +++ b/core/modules/datetime/datetime.module @@ -227,13 +227,11 @@ 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, - ); - } + $form_required_marker = array( + '#theme' => 'form_required_marker', + '#element' => $element + ); + $variables['required'] = !empty($element['#required']) ? drupal_render($form_required_marker) : ''; if (!empty($element['#title'])) { $variables['title'] = $element['#title']; diff --git a/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeFieldTest.php b/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeFieldTest.php index 76b4cb9..ec62ca3 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeFieldTest.php +++ b/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeFieldTest.php @@ -69,6 +69,7 @@ function setUp() { 'field_name' => $this->field->name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', + 'required' => TRUE, )); $this->instance->save(); @@ -97,6 +98,7 @@ function testDateField() { // Display creation form. $this->drupalGet('entity_test/add'); $this->assertFieldByName("{$field_name}[0][value][date]", '', 'Date element found.'); + $this->assertFieldByXPath('//*[@id="' . $field_name . '-add-more-wrapper"]/h4/span', '*', 'Required markup found'); $this->assertNoFieldByName("{$field_name}[0][value][time]", '', 'Time element not found.'); // Submit a valid date and ensure it is accepted.