class DateRangePlainFormatter
Same name in other branches
- 9 core/modules/datetime_range/src/Plugin/Field/FieldFormatter/DateRangePlainFormatter.php \Drupal\datetime_range\Plugin\Field\FieldFormatter\DateRangePlainFormatter
- 8.9.x core/modules/datetime_range/src/Plugin/Field/FieldFormatter/DateRangePlainFormatter.php \Drupal\datetime_range\Plugin\Field\FieldFormatter\DateRangePlainFormatter
- 11.x core/modules/datetime_range/src/Plugin/Field/FieldFormatter/DateRangePlainFormatter.php \Drupal\datetime_range\Plugin\Field\FieldFormatter\DateRangePlainFormatter
Plugin implementation of the 'Plain' formatter for 'daterange' fields.
This formatter renders the data range as a plain text string, with a configurable separator using an ISO-like date format string.
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_range\Plugin\Field\FieldFormatter\DateRangePlainFormatter extends \Drupal\datetime\Plugin\Field\FieldFormatter\DateTimePlainFormatter uses \Drupal\datetime_range\DateTimeRangeTrait
- 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 DateRangePlainFormatter
2 files declare their use of DateRangePlainFormatter
- datetime_range.module in core/
modules/ datetime_range/ datetime_range.module - Field hooks to implement a datetime field that stores a start and end date.
- datetime_range.post_update.php in core/
modules/ datetime_range/ datetime_range.post_update.php - Post-update functions for Datetime Range module.
File
-
core/
modules/ datetime_range/ src/ Plugin/ Field/ FieldFormatter/ DateRangePlainFormatter.php, line 18
Namespace
Drupal\datetime_range\Plugin\Field\FieldFormatterView source
class DateRangePlainFormatter extends DateTimePlainFormatter {
use DateTimeRangeTrait;
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return static::dateTimeRangeDefaultSettings() + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
$separator = $this->getSetting('separator');
foreach ($items as $delta => $item) {
if (!empty($item->start_date) && !empty($item->end_date)) {
/** @var \Drupal\Core\Datetime\DrupalDateTime $start_date */
$start_date = $item->start_date;
/** @var \Drupal\Core\Datetime\DrupalDateTime $end_date */
$end_date = $item->end_date;
if ($start_date->getTimestamp() !== $end_date->getTimestamp()) {
$elements[$delta] = $this->renderStartEnd($start_date, $separator, $end_date);
}
else {
$elements[$delta] = $this->buildDate($start_date);
if (!empty($item->_attributes)) {
$elements[$delta]['#attributes'] += $item->_attributes;
// Unset field item attributes since they have been included in the
// formatter output and should not be rendered in the field template.
unset($item->_attributes);
}
}
}
}
return $elements;
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
$form = $this->dateTimeRangeSettingsForm($form);
return $form;
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
return array_merge(parent::settingsSummary(), $this->dateTimeRangeSettingsSummary());
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.