DateRangeDefaultFormatter.php in Drupal 10
File
core/modules/datetime_range/src/Plugin/Field/FieldFormatter/DateRangeDefaultFormatter.php
View source
<?php
namespace Drupal\datetime_range\Plugin\Field\FieldFormatter;
use Drupal\Core\Form\FormStateInterface;
use Drupal\datetime\Plugin\Field\FieldFormatter\DateTimeDefaultFormatter;
use Drupal\datetime_range\DateTimeRangeTrait;
class DateRangeDefaultFormatter extends DateTimeDefaultFormatter {
use DateTimeRangeTrait;
public static function defaultSettings() {
return [
'separator' => '-',
] + parent::defaultSettings();
}
public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
$form['separator'] = [
'#type' => 'textfield',
'#title' => $this
->t('Date separator'),
'#description' => $this
->t('The string to separate the start and end dates'),
'#default_value' => $this
->getSetting('separator'),
];
return $form;
}
public function settingsSummary() {
$summary = parent::settingsSummary();
if ($separator = $this
->getSetting('separator')) {
$summary[] = $this
->t('Separator: %separator', [
'%separator' => $separator,
]);
}
return $summary;
}
}