DateRangeAllDayDefaultFormatter.php in Date all day 8
File
src/Plugin/Field/FieldFormatter/DateRangeAllDayDefaultFormatter.php
View source
<?php
namespace Drupal\date_all_day\Plugin\Field\FieldFormatter;
use Drupal\Core\Form\FormStateInterface;
use Drupal\datetime_range\Plugin\Field\FieldFormatter\DateRangeDefaultFormatter;
class DateRangeAllDayDefaultFormatter extends DateRangeDefaultFormatter {
use DateRangeAllDayTrait;
public static function defaultSettings() {
return [
'date_only_format' => 'date_all_day',
] + parent::defaultSettings();
}
public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
$options = $form['format_type']['#options'];
$form['date_only_format'] = [
'#type' => 'select',
'#title' => $this
->t('Date only format'),
'#description' => $this
->t('A date format excluding the time part. This is used when the "all day" option is active.'),
'#options' => $options,
'#default_value' => $this
->getSetting('date_only_format'),
];
return $form;
}
protected function formatDate($date, $all_day = FALSE) {
$format_setting_name = $all_day ? 'date_only_format' : 'format_type';
$format_type = $this
->getSetting($format_setting_name);
$timezone = $this
->getSetting('timezone_override') ?: $date
->getTimezone()
->getName();
return $this->dateFormatter
->format($date
->getTimestamp(), $format_type, '', $timezone != '' ? $timezone : NULL);
}
}