class DateTimePlainFormatter
Same name in other branches
- 9 core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimePlainFormatter
- 8.9.x core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimePlainFormatter
- 10 core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimePlainFormatter
Plugin implementation of the 'Plain' formatter for 'datetime' fields.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
- class \Drupal\Core\Field\PluginSettingsBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Field\PluginSettingsInterface, \Drupal\Component\Plugin\DependentPluginInterface
- class \Drupal\Core\Field\FormatterBase extends \Drupal\Core\Field\PluginSettingsBase implements \Drupal\Core\Field\FormatterInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface
- class \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeFormatterBase extends \Drupal\Core\Field\FormatterBase
- class \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimePlainFormatter extends \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeFormatterBase
- class \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeFormatterBase extends \Drupal\Core\Field\FormatterBase
- class \Drupal\Core\Field\FormatterBase extends \Drupal\Core\Field\PluginSettingsBase implements \Drupal\Core\Field\FormatterInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface
- class \Drupal\Core\Field\PluginSettingsBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Field\PluginSettingsInterface, \Drupal\Component\Plugin\DependentPluginInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
Expanded class hierarchy of DateTimePlainFormatter
1 file declares its use of DateTimePlainFormatter
- DateRangePlainFormatter.php in core/
modules/ datetime_range/ src/ Plugin/ Field/ FieldFormatter/ DateRangePlainFormatter.php
File
-
core/
modules/ datetime/ src/ Plugin/ Field/ FieldFormatter/ DateTimePlainFormatter.php, line 14
Namespace
Drupal\datetime\Plugin\Field\FieldFormatterView source
class DateTimePlainFormatter extends DateTimeFormatterBase {
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($items as $delta => $item) {
if (!empty($item->date)) {
/** @var \Drupal\Core\Datetime\DrupalDateTime $date */
$date = $item->date;
$elements[$delta] = $this->buildDate($date);
}
}
return $elements;
}
/**
* {@inheritdoc}
*/
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);
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.