diff --git a/core/modules/datetime/config/schema/datetime.schema.yml b/core/modules/datetime/config/schema/datetime.schema.yml index 200751a..a5c50b1 100644 --- a/core/modules/datetime/config/schema/datetime.schema.yml +++ b/core/modules/datetime/config/schema/datetime.schema.yml @@ -1,6 +1,6 @@ # Schema for the configuration files of the Datetime module. -# datetime +# Datetime file type. field.storage_settings.datetime: type: mapping @@ -86,7 +86,7 @@ field.widget.settings.datetime_default: type: mapping label: 'Datetime default display format settings' -# daterange +# Daterange field type. field.storage_settings.daterange: type: mapping diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeCustomFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeCustomFormatter.php index 6422759..909f86f 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeCustomFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeCustomFormatter.php @@ -5,6 +5,7 @@ use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\datetime\Plugin\Field\FieldType\DateRangeItem; /** * Plugin implementation of the 'Custom' formatter for 'daterange' fields. @@ -42,7 +43,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) { /** @var \Drupal\Core\Datetime\DrupalDateTime $end_date */ $end_date = $item->end_date; - if ($this->getFieldSetting('daterange_type') == 'date') { + if ($this->getFieldSetting('daterange_type') == DateRangeItem::DATERANGE_TYPE_DATE) { // A date without time will pick up the current time, use the default. datetime_date_default_time($start_date); datetime_date_default_time($end_date); @@ -105,7 +106,7 @@ public function settingsForm(array $form, FormStateInterface $form_state) { public function settingsSummary() { $summary = parent::settingsSummary(); - $date = DrupalDateTime::createFromTimestamp(REQUEST_TIME); + $date = DrupalDateTime::createFromTimestamp($this->requestStack->getCurrentRequest()->server->get('REQUEST_TIME')); $this->setTimeZone($date); $summary[] = $this->t('Format: @display', ['@display' => $this->formatDate($date)]); diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeDefaultFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeDefaultFormatter.php index 55c1b94..785fa9a 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeDefaultFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeDefaultFormatter.php @@ -5,6 +5,7 @@ use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\datetime\Plugin\Field\FieldType\DateRangeItem; /** * Plugin implementation of the 'Default' formatter for 'daterange' fields. @@ -42,7 +43,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) { /** @var \Drupal\Core\Datetime\DrupalDateTime $end_date */ $end_date = $item->end_date; - if ($this->getFieldSetting('daterange_type') == 'date') { + if ($this->getFieldSetting('daterange_type') == DateRangeItem::DATERANGE_TYPE_DATE) { // A date without time will pick up the current time, use the default. datetime_date_default_time($start_date); datetime_date_default_time($end_date); @@ -149,7 +150,7 @@ public function settingsForm(array $form, FormStateInterface $form_state) { public function settingsSummary() { $summary = parent::settingsSummary(); - $date = DrupalDateTime::createFromTimestamp(REQUEST_TIME); + $date = DrupalDateTime::createFromTimestamp($this->requestStack->getCurrentRequest()->server->get('REQUEST_TIME')); $this->setTimeZone($date); $summary[] = $this->t('Format: @display', ['@display' => $this->formatDate($date)]); diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeFormatterBase.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeFormatterBase.php index 9db9053..befe395 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeFormatterBase.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangeFormatterBase.php @@ -10,6 +10,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\RequestStack; /** @@ -32,6 +33,13 @@ protected $dateFormatStorage; /** + * The request stack. + * + * @var \Symfony\Component\HttpFoundation\RequestStack + */ + protected $requestStack; + + /** * Constructs a new DateTimeDefaultFormatter. * * @param string $plugin_id @@ -52,12 +60,15 @@ * The date formatter service. * @param \Drupal\Core\Entity\EntityStorageInterface $date_format_storage * The date format entity storage. + * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack + * The request stack used to retrieve the current request. */ - public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, DateFormatterInterface $date_formatter, EntityStorageInterface $date_format_storage) { + public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, DateFormatterInterface $date_formatter, EntityStorageInterface $date_format_storage, RequestStack $request_stack) { parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings); $this->dateFormatter = $date_formatter; $this->dateFormatStorage = $date_format_storage; + $this->requestStack = $request_stack; } /** @@ -73,7 +84,8 @@ public static function create(ContainerInterface $container, array $configuratio $configuration['view_mode'], $configuration['third_party_settings'], $container->get('date.formatter'), - $container->get('entity.manager')->getStorage('date_format') + $container->get('entity.manager')->getStorage('date_format'), + $container->get('request_stack') ); } diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangePlainFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangePlainFormatter.php index 19a5f14..7b77a06 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangePlainFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateRangePlainFormatter.php @@ -3,6 +3,7 @@ namespace Drupal\datetime\Plugin\Field\FieldFormatter; use Drupal\Core\Field\FieldItemListInterface; +use Drupal\datetime\Plugin\Field\FieldType\DateRangeItem; /** * Plugin implementation of the 'Plain' formatter for 'daterange' fields. @@ -13,7 +14,7 @@ * field_types = { * "daterange" * } - *) + * ) */ class DateRangePlainFormatter extends DateRangeFormatterBase { @@ -31,7 +32,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) { /** @var \Drupal\Core\Datetime\DrupalDateTime $end_date */ $end_date = $item->end_date; - if ($this->getFieldSetting('daterange_type') == 'date') { + if ($this->getFieldSetting('daterange_type') == DateRangeItem::DATERANGE_TYPE_DATE) { // A date without time will pick up the current time, use the default. datetime_date_default_time($start_date); datetime_date_default_time($end_date); @@ -67,7 +68,7 @@ public function viewElements(FieldItemListInterface $items, $langcode) { * {@inheritdoc} */ protected function formatDate($date) { - $format = $this->getFieldSetting('daterange_type') == 'date' ? DATETIME_DATE_STORAGE_FORMAT : DATETIME_DATETIME_STORAGE_FORMAT; + $format = $this->getFieldSetting('daterange_type') == DateRangeItem::DATERANGE_TYPE_DATE ? DATETIME_DATE_STORAGE_FORMAT : DATETIME_DATETIME_STORAGE_FORMAT; $timezone = $this->getSetting('timezone_override'); return $this->dateFormatter->format($date->getTimestamp(), 'custom', $format, $timezone != '' ? $timezone : NULL); } diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php index 678ddc8..c4abd2d 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeCustomFormatter.php @@ -15,7 +15,7 @@ * field_types = { * "datetime" * } - *) + * ) */ class DateTimeCustomFormatter extends DateTimeFormatterBase { diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php index 683d75c..a74810a 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimePlainFormatter.php @@ -14,7 +14,7 @@ * field_types = { * "datetime" * } - *) + * ) */ class DateTimePlainFormatter extends DateTimeFormatterBase { diff --git a/core/modules/datetime/src/Plugin/Field/FieldWidget/DateRangeDatelistWidget.php b/core/modules/datetime/src/Plugin/Field/FieldWidget/DateRangeDatelistWidget.php index a918213..f92955c 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldWidget/DateRangeDatelistWidget.php +++ b/core/modules/datetime/src/Plugin/Field/FieldWidget/DateRangeDatelistWidget.php @@ -103,7 +103,7 @@ function settingsForm(array $form, FormStateInterface $form_state) { '#options' => array('MDY' => t('Month/Day/Year'), 'DMY' => t('Day/Month/Year'), 'YMD' => t('Year/Month/Day')), ); - if ($this->getFieldSetting('daterange_type') == 'datetime') { + if ($this->getFieldSetting('daterange_type') == DateRangeItem::DATERANGE_TYPE_DATETIME) { $element['time_type'] = array( '#type' => 'select', '#title' => t('Time type'), @@ -146,7 +146,7 @@ public function settingsSummary() { $summary = array(); $summary[] = t('Date part order: @order', array('@order' => $this->getSetting('date_order'))); - if ($this->getFieldSetting('daterange_type') == 'datetime') { + if ($this->getFieldSetting('daterange_type') == DateRangeItem::DATERANGE_TYPE_DATETIME) { $summary[] = t('Time type: @time_type', array('@time_type' => $this->getSetting('time_type'))); $summary[] = t('Time increments: @increment', array('@increment' => $this->getSetting('increment'))); }