3 namespace Drupal\datetime\Plugin\Field\FieldFormatter;
5 use Drupal\Core\Field\FieldItemListInterface;
6 use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
9 * Plugin implementation of the 'Plain' formatter for 'datetime' fields.
12 * id = "datetime_plain",
13 * label = @Translation("Plain"),
19 class DateTimePlainFormatter extends DateTimeFormatterBase {
24 public function viewElements(FieldItemListInterface $items, $langcode) {
27 foreach ($items as $delta => $item) {
29 if (!empty($item->date)) {
30 /** @var \Drupal\Core\Datetime\DrupalDateTime $date */
33 if ($this->getFieldSetting('datetime_type') == 'date') {
34 // A date without time will pick up the current time, use the default.
35 datetime_date_default_time($date);
37 $this->setTimeZone($date);
39 $output = $this->formatDate($date);
57 protected function formatDate($date) {
58 $format = $this->getFieldSetting('datetime_type') == DateTimeItem::DATETIME_TYPE_DATE ? DATETIME_DATE_STORAGE_FORMAT : DATETIME_DATETIME_STORAGE_FORMAT;
59 $timezone = $this->getSetting('timezone_override');
60 return $this->dateFormatter->format($date->getTimestamp(), 'custom', $format, $timezone != '' ? $timezone : NULL);