diff --git a/core/lib/Drupal/Core/Datetime/Element/Datetime.php b/core/lib/Drupal/Core/Datetime/Element/Datetime.php index 9a83720565874c40fe994e670be07a851243ec48..2eaf15d57bad5dff78e982392b82ea8ca363a728 100644 --- a/core/lib/Drupal/Core/Datetime/Element/Datetime.php +++ b/core/lib/Drupal/Core/Datetime/Element/Datetime.php @@ -239,7 +239,6 @@ public static function processDatetime(&$element, FormStateInterface $form_state // placeholders are invalid for HTML5 date and datetime, so an example // format is appended to the title to appear in tooltips. $extra_attributes = [ - 'title' => t('Date (e.g. @format)', ['@format' => static::formatExample($date_format)]), 'type' => $element['#date_date_element'], ]; @@ -285,7 +284,6 @@ public static function processDatetime(&$element, FormStateInterface $form_state // Adds the HTML5 attributes. $extra_attributes = [ - 'title' => t('Time (e.g. @format)', ['@format' => static::formatExample($time_format)]), 'type' => $element['#date_time_element'], 'step' => $element['#date_increment'], ]; @@ -352,9 +350,6 @@ public static function validateDatetime(&$element, FormStateInterface $form_stat if ($input_exists) { $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); // If there's empty input and the field is not required, set it to empty. if (empty($input['date']) && empty($input['time']) && !$element['#required']) { @@ -363,7 +358,7 @@ public static function validateDatetime(&$element, FormStateInterface $form_stat // If there's empty input and the field is required, set an error. A // reminder of the required format in the message provides a good UX. elseif (empty($input['date']) && empty($input['time']) && $element['#required']) { - $form_state->setError($element, t('The %field date is required. Enter a date in the format %format.', ['%field' => $title, '%format' => static::formatExample($format)])); + $form_state->setError($element, t('The %field date is required.', ['%field' => $title])); } else { // If the date is valid, set it. @@ -374,7 +369,7 @@ public static function validateDatetime(&$element, FormStateInterface $form_stat // If the date is invalid, set an error. A reminder of the required // format in the message provides a good UX. else { - $form_state->setError($element, t('The %field date is invalid. Enter a date in the format %format.', ['%field' => $title, '%format' => static::formatExample($format)])); + $form_state->setError($element, t('The %field date is invalid. Enter a date in the correct format.', ['%field' => $title])); } } } @@ -389,8 +384,14 @@ public static function validateDatetime(&$element, FormStateInterface $form_stat * The date format. * * @return string + * + * @deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. + * There is no replacement. + * + * @see https://www.drupal.org/node/3385058 */ public static function formatExample($format) { + @trigger_error(__METHOD__ . ' is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3385058', E_USER_DEPRECATED); if (!static::$dateExample) { static::$dateExample = new DrupalDateTime(); } diff --git a/core/lib/Drupal/Core/Datetime/Plugin/Field/FieldWidget/TimestampDatetimeWidget.php b/core/lib/Drupal/Core/Datetime/Plugin/Field/FieldWidget/TimestampDatetimeWidget.php index 0ebe7b52d5c9236911e4daeaf77579d7f22037a5..af3fd0dcee2135e3e8a4d1d2c797379f85ed6621 100644 --- a/core/lib/Drupal/Core/Datetime/Plugin/Field/FieldWidget/TimestampDatetimeWidget.php +++ b/core/lib/Drupal/Core/Datetime/Plugin/Field/FieldWidget/TimestampDatetimeWidget.php @@ -3,8 +3,6 @@ namespace Drupal\Core\Datetime\Plugin\Field\FieldWidget; use Drupal\Core\Datetime\DrupalDateTime; -use Drupal\Core\Datetime\Element\Datetime; -use Drupal\Core\Datetime\Entity\DateFormat; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\WidgetBase; use Drupal\Core\Form\FormStateInterface; @@ -27,9 +25,8 @@ class TimestampDatetimeWidget extends WidgetBase { * {@inheritdoc} */ public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { - $date_format = DateFormat::load('html_date')->getPattern(); - $time_format = DateFormat::load('html_time')->getPattern(); - $default_value = isset($items[$delta]->value) ? DrupalDateTime::createFromTimestamp($items[$delta]->value) : ''; + $parent_entity = $items->getParent()->getValue(); + $default_value = (!$parent_entity->isNew() && isset($items[$delta]->value)) ? DrupalDateTime::createFromTimestamp($items[$delta]->value) : ''; $element['value'] = $element + [ '#type' => 'datetime', '#default_value' => $default_value, @@ -38,9 +35,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $element['value']['#description'] = $element['#description'] !== '' ? $element['#description'] - : $this->t('Format: %format. Leave blank to use the time of form submission.', - ['%format' => Datetime::formatExample($date_format . ' ' . $time_format)]); - + : $this->t('Leave blank to use the time of form submission.'); return $element; } diff --git a/core/modules/content_translation/src/ContentTranslationHandler.php b/core/modules/content_translation/src/ContentTranslationHandler.php index d3dad8ee8044882f7667383ec728404af0946652..b4911b60afa37d7e0d2150f0a021ec46b4446377 100644 --- a/core/modules/content_translation/src/ContentTranslationHandler.php +++ b/core/modules/content_translation/src/ContentTranslationHandler.php @@ -541,10 +541,7 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, En '#type' => 'textfield', '#title' => t('Authored on'), '#maxlength' => 25, - '#description' => t('Format: %time. The date format is YYYY-MM-DD and %timezone is the time zone offset from UTC. Leave blank to use the time of form submission.', [ - '%time' => $this->dateFormatter->format(REQUEST_TIME, 'custom', 'Y-m-d H:i:s O'), - '%timezone' => $this->dateFormatter->format(REQUEST_TIME, 'custom', 'O'), - ]), + '#description' => t('Leave blank to use the time of form submission.'), '#default_value' => $new_translation || !$date ? '' : $this->dateFormatter->format($date, 'custom', 'Y-m-d H:i:s O'), ]; diff --git a/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php b/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php index 67d8c328da62cc2d353484cdf79c4657664febfa..ca201a398f72376e507bca26ac4e4f15f17969fa 100644 --- a/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php +++ b/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php @@ -393,12 +393,9 @@ public function testDatetimeField() { $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. Enter a date in the format %format.', ['%field' => $field_label, '%format' => $arguments['%format']]); + $expected_error_message = new FormattableMarkup('The %field date is required.', ['%field' => $field_label]); $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']); } /** diff --git a/core/phpstan-baseline.neon b/core/phpstan-baseline.neon index e975c5f19b10ea13808329afc7b8ad0315e3759e..7857f7891789865ba1d622f33f86524cec19549a 100644 --- a/core/phpstan-baseline.neon +++ b/core/phpstan-baseline.neon @@ -1154,7 +1154,7 @@ parameters: - message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#" - count: 5 + count: 3 path: modules/content_translation/src/ContentTranslationHandler.php -