Unverified Commit 1aaa480b authored by Sally Young's avatar Sally Young
Browse files

Issue #3354606 by ranjith_kumar_k_u, pascalim, Abhijith S, smustgrave,...

Issue #3354606 by ranjith_kumar_k_u, pascalim, Abhijith S, smustgrave, borisson_: Datetime field name missing from validation error message
parent a50411ad
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -351,7 +351,7 @@ public static function validateDatetime(&$element, FormStateInterface $form_stat
    $input = NestedArray::getValue($form_state->getValues(), $element['#parents'], $input_exists);
    if ($input_exists) {

      $title = !empty($element['#title']) ? $element['#title'] : '';
      $title = static::getElementTitle($element, $complete_form);
      $date_format = $element['#date_date_element'] != 'none' ? static::getHtml5DateFormat($element) : '';
      $time_format = $element['#date_time_element'] != 'none' ? static::getHtml5TimeFormat($element) : '';
      $format = trim($date_format . ' ' . $time_format);
+14 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\node\Entity\Node;
use Drupal\Core\Form\FormState;

/**
 * Tests Datetime field functionality.
@@ -385,6 +386,19 @@ public function testDatetimeField() {
    ]);
    $output = $this->renderTestEntity($id);
    $this->assertStringContainsString((string) $expected, $output, new FormattableMarkup('Formatted date field using datetime_time_ago format displayed as %expected.', ['%expected' => $expected]));

    // Test the required field validation error message.
    $entity = EntityTest::create(['name' => 'test datetime required message']);
    $form = \Drupal::entityTypeManager()->getFormObject('entity_test', 'default')->setEntity($entity);
    $form_state = new FormState();
    \Drupal::formBuilder()->submitForm($form, $form_state);
    $errors = $form_state->getErrors();
    $arguments = $errors["{$field_name}][0][value"]->getArguments();
    $expected_error_message = new FormattableMarkup('The %field date is required. Please enter a date in the format %format.', ['%field' => $field_label, '%format' => $arguments['%format']]);
    $actual_error_message = $errors["{$field_name}][0][value"]->__toString();
    $this->assertEquals($expected_error_message->__toString(), $actual_error_message);
    // Verify the format value is in the "YYYY-MM-DD HH:MM:SS" format.
    $this->assertMatchesRegularExpression('/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/', $arguments['%format']);
  }

  /**