Skip to content
Snippets Groups Projects
Commit 5404ebfb authored by catch's avatar catch
Browse files

Issue #2791693 by nginex, acbramley, oknate, guaneagler, jan kellermann,...

Issue #2791693 by nginex, acbramley, oknate, guaneagler, jan kellermann, jonathan1055, jibran, ankithashetty, dpi, Jelle_S, FeyP, kattekrab, smustgrave, mpdonadio, quietone, AaronMcHale, rkoller, BlackBamboo, simohell, Jody Lynn, shaal, notmike: Remove sample date from date field error message and title attribute
parent d251a98e
No related branches found
No related tags found
No related merge requests found
......@@ -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();
}
......
......@@ -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;
}
......
......@@ -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'),
];
......
......@@ -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']);
}
/**
......
......@@ -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
-
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment