Skip to content

Commit

Permalink
Fix added for replacement of Datetime::formatExample()
Browse files Browse the repository at this point in the history
  • Loading branch information
kedarkhaire committed Feb 14, 2025
1 parent f2a159a commit 6a38553
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/Plugin/Field/FieldWidget/DatestampWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
namespace Drupal\apigee_m10n\Plugin\Field\FieldWidget;

use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Datetime\Element\Datetime;
use Drupal\Core\Datetime\Entity\DateFormat;
use Drupal\Core\Datetime\Plugin\Field\FieldWidget\TimestampDatetimeWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
Expand All @@ -39,12 +37,17 @@
*/
class DatestampWidget extends TimestampDatetimeWidget {

/**
* Example format used as Datetime::formatExample is removed from D11.
*
* @var string
*/
public const DATESTAMPFORMAT = 'YYYY-MM-DD hh:mm:ss';

/**
* {@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->getTimestamp()) : '';
$element['value'] = $element + [
'#type' => 'datetime',
Expand All @@ -53,7 +56,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
'#date_time_element' => 'none',
'#date_year_range' => '1902:2037',
];
$element['value']['#description'] = $this->t('Format: %format. Leave blank to use the time of form submission.', ['%format' => Datetime::formatExample($date_format . ' ' . $time_format)]);
$element['value']['#description'] = $this->t('Format: %format. Leave blank to use the time of form submission.', ['%format' => static::DATESTAMPFORMAT]);

return $element;
}
Expand Down

0 comments on commit 6a38553

Please sign in to comment.