function TimestampFormatter::settingsSummary
Same name in other branches
- 9 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\TimestampFormatter::settingsSummary()
- 8.9.x core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\TimestampFormatter::settingsSummary()
- 10 core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampFormatter.php \Drupal\Core\Field\Plugin\Field\FieldFormatter\TimestampFormatter::settingsSummary()
Overrides FormatterBase::settingsSummary
File
-
core/
lib/ Drupal/ Core/ Field/ Plugin/ Field/ FieldFormatter/ TimestampFormatter.php, line 235
Class
- TimestampFormatter
- Plugin implementation of the 'timestamp' formatter.
Namespace
Drupal\Core\Field\Plugin\Field\FieldFormatterCode
public function settingsSummary() {
$summary = parent::settingsSummary();
$time_diff = $this->getSetting('time_diff');
$date_format = $this->getSetting('date_format');
$date_format = $date_format === static::CUSTOM_DATE_FORMAT ? $this->getSetting('custom_date_format') : $date_format;
if ($time_diff['enabled']) {
$summary[] = $this->t('Displayed as a time difference');
$options = [
'granularity' => $time_diff['granularity'],
];
$timestamp = strtotime('1 year 1 month 1 week 1 day 1 hour 1 minute');
$interval = $this->dateFormatter
->formatTimeDiffUntil($timestamp, $options);
$display = new FormattableMarkup($time_diff['future_format'], [
'@interval' => $interval,
]);
$summary[] = $this->t('Future date: %display', [
'%display' => $display,
]);
$timestamp = strtotime('-1 year -1 month -1 week -1 day -1 hour -1 minute');
$interval = $this->dateFormatter
->formatTimeDiffSince($timestamp, $options);
$display = new FormattableMarkup($time_diff['past_format'], [
'@interval' => $interval,
]);
$summary[] = $this->t('Past date: %display', [
'%display' => $display,
]);
if ($time_diff['refresh']) {
$refresh_intervals = $this->getRefreshIntervals();
$summary[] = $this->t('Refresh every @interval', [
'@interval' => $refresh_intervals[$time_diff['refresh']],
]);
}
$summary[] = $this->t('Disabled JavaScript format: @date_format', [
'@date_format' => $date_format,
]);
}
else {
$summary[] = $this->t('Date format: @date_format', [
'@date_format' => $date_format,
]);
}
$tooltip = $this->getSetting('tooltip');
if (!empty($tooltip['date_format'])) {
$tooltip_date_format = $tooltip['date_format'];
$tooltip_date_format = $tooltip_date_format === static::CUSTOM_DATE_FORMAT ? $tooltip['custom_date_format'] : $tooltip_date_format;
$summary[] = $this->t('Tooltip date format: @date_format', [
'@date_format' => $tooltip_date_format,
]);
}
if ($timezone = $this->getSetting('timezone')) {
$summary[] = $this->t('Time zone: @timezone', [
'@timezone' => $timezone,
]);
}
return $summary;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.