DateTimePlainFormatter.php in Drupal 10
File
core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php
View source
<?php
namespace Drupal\datetime\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
class DateTimePlainFormatter extends DateTimeFormatterBase {
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($items as $delta => $item) {
if (!empty($item->date)) {
$date = $item->date;
$elements[$delta] = $this
->buildDate($date);
}
}
return $elements;
}
protected function formatDate($date) {
$format = $this
->getFieldSetting('datetime_type') == DateTimeItem::DATETIME_TYPE_DATE ? DateTimeItemInterface::DATE_STORAGE_FORMAT : DateTimeItemInterface::DATETIME_STORAGE_FORMAT;
$timezone = $this
->getSetting('timezone_override') ?: $date
->getTimezone()
->getName();
return $this->dateFormatter
->format($date
->getTimestamp(), 'custom', $format, $timezone != '' ? $timezone : NULL);
}
}