reverted:
--- b/modules/contrib/datetime_extras/Add_datetime_range_formatter_2834016_4.patch
+++ /dev/null
@@ -1,394 +0,0 @@
-diff --git a/datetime_extras.info.yml b/datetime_extras.info.yml
-new file mode 100644
-index 0000000..4c20faf
---- /dev/null
-+++ b/datetime_extras.info.yml
-@@ -0,0 +1,9 @@
-+name: 'Datetime Extras'
-+type: module
-+description: 'Provides the extra widgets and formatters for datetime module.'
-+package: Custom
-+version: 8.0-dev
-+core: 8.x
-+dependencies:
-+ - datetime
-+ - datetime_range
-diff --git a/datetime_extras.module b/datetime_extras.module
-new file mode 100644
-index 0000000..af825ed
---- /dev/null
-+++ b/datetime_extras.module
-@@ -0,0 +1,28 @@
-+' . t('About') . '';
-+ $output .= '
' . t('The Datetime Range module provides a Date field that stores start dates and times, as well as end dates and times. See the Field module help and the Field UI module help pages for general information on fields and how to create and manage them. For more information, see the online documentation for the Datetime Range module.', array(':field' => \Drupal::url('help.page', array('name' => 'field')), ':field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? \Drupal::url('help.page', array('name' => 'field_ui')) : '#', ':datetime_do' => 'https://www.drupal.org/documentation/modules/datetime_range')) . '
';
-+ $output .= '' . t('Uses') . '
';
-+ $output .= '';
-+ $output .= '- ' . t('Managing and displaying date fields') . '
';
-+ $output .= '- ' . t('The settings and the display of the Date field can be configured separately. See the Field UI help for more information on how to manage fields and their display.', array(':field_ui' => (\Drupal::moduleHandler()->moduleExists('field_ui')) ? \Drupal::url('help.page', array('name' => 'field_ui')) : '#')) . '
';
-+ $output .= '- ' . t('Displaying dates') . '
';
-+ $output .= '- ' . t('Dates can be displayed using the Plain or the Default formatter. The Plain formatter displays the date in the ISO 8601 format. If you choose the Default formatter, you can choose a format from a predefined list that can be managed on the Date and time formats page.', array(':date_format_list' => \Drupal::url('entity.date_format.collection'))) . '
';
-+ $output .= '
';
-+ return $output;
-+ }
-+}
-diff --git a/src/DateTimeExtraTrait.php b/src/DateTimeExtraTrait.php
-new file mode 100644
-index 0000000..4303d2b
---- /dev/null
-+++ b/src/DateTimeExtraTrait.php
-@@ -0,0 +1,50 @@
-+getFieldSetting('datetime_type') == DateTimeItem::DATETIME_TYPE_DATE) {
-+ // A date without time will pick up the current time, use the default.
-+ datetime_date_default_time($date);
-+ }
-+
-+ // Create the ISO date in Universal Time.
-+ $iso_date = $date->format("Y-m-d\TH:i:s") . 'Z';
-+
-+ $this->setTimeZone($date);
-+
-+ $build = [
-+ '#theme' => 'time',
-+ '#text' => $this->formatDate($date, $format),
-+ '#html' => FALSE,
-+ '#attributes' => [
-+ 'datetime' => $iso_date,
-+ ],
-+ '#cache' => [
-+ 'contexts' => [
-+ 'timezone',
-+ ],
-+ ],
-+ ];
-+
-+ return $build;
-+ }
-+
-+}
-diff --git a/src/Plugin/Field/FieldFormatter/DateRangeNiceFormatter.php b/src/Plugin/Field/FieldFormatter/DateRangeNiceFormatter.php
-new file mode 100644
-index 0000000..e55f93f
---- /dev/null
-+++ b/src/Plugin/Field/FieldFormatter/DateRangeNiceFormatter.php
-@@ -0,0 +1,176 @@
-+ elements, with
-+ * configurable date formats (from the list of configured formats) and a
-+ * separator.
-+ *
-+ * @FieldFormatter(
-+ * id = "daterange_nice",
-+ * label = @Translation("Nice"),
-+ * field_types = {
-+ * "daterange"
-+ * }
-+ * )
-+ */
-+class DateRangeNiceFormatter extends DateTimeDefaultFormatter {
-+
-+ use DateTimeExtraTrait;
-+
-+ /**
-+ * {@inheritdoc}
-+ */
-+ public static function defaultSettings() {
-+ return [
-+ 'separator' => '-',
-+ ] + 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;
-+ $format_types = $this->niceFormats();
-+
-+ if ($start_date->format('U') !== $end_date->format('U')) {
-+ $format_start =
-+ $format_end = $format_types[$this->getSetting('format_type')]['format'];
-+ if ($start_date->format('Y-m-d') == $end_date->format('Y-m-d')) {
-+ $format_start = $format_types[$this->getSetting('format_type')]['format_time_start'];
-+ $format_end = $format_types[$this->getSetting('format_type')]['format_time_end'];
-+ }
-+ else if ($start_date->format('Y-m') == $end_date->format('Y-m')) {
-+ $format_start = $format_types[$this->getSetting('format_type')]['format_day_start'];
-+ $format_end = $format_types[$this->getSetting('format_type')]['format_day_end'];
-+ }
-+ else if ($start_date->format('Y') == $end_date->format('Y')) {
-+ $format_start = $format_types[$this->getSetting('format_type')]['format_month_start'];
-+ $format_end = $format_types[$this->getSetting('format_type')]['format_month_end'];
-+ }
-+ else {
-+ $format_start = $format_types[$this->getSetting('format_type')]['format_year_start'];
-+ $format_end = $format_types[$this->getSetting('format_type')]['format_year_end'];
-+ }
-+ $elements[$delta] = [
-+ 'start_date' => $this->buildDateWithIsoAttribute($start_date, $format_start),
-+ 'separator' => ['#plain_text' => ' ' . $separator . ' '],
-+ 'end_date' => $this->buildDateWithIsoAttribute($end_date, $format_end),
-+ ];
-+ }
-+ else {
-+ 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}
-+ */
-+ protected function formatDate($date, $format = NULL) {
-+ $format_type = 'custom';
-+ $format = $format ? $format : 'm/d/Y';
-+ $timezone = $this->getSetting('timezone_override') ?: $date->getTimezone()->getName();
-+ return $this->dateFormatter->format($date->getTimestamp(), $format_type, $format, $timezone != '' ? $timezone : NULL);
-+ }
-+
-+ /**
-+ * {@inheritdoc}
-+ */
-+ public function settingsForm(array $form, FormStateInterface $form_state) {
-+ $form = parent::settingsForm($form, $form_state);
-+
-+ $time = new DrupalDateTime();
-+ $format_types = $this->niceFormats();
-+ $options = [];
-+ foreach ($format_types as $type => $type_info) {
-+ $format = $this->dateFormatter->format($time->format('U'), 'custom', $type_info['format']);
-+ $options[$type] = $type_info['label'] . ' (' . $format . ')';
-+ }
-+
-+ $form['format_type'] = array(
-+ '#type' => 'select',
-+ '#title' => t('Date format'),
-+ '#description' => t("Choose a format for displaying the date. Be sure to set a format appropriate for the field, i.e. omitting time for a field that only has a date."),
-+ '#options' => $options,
-+ '#default_value' => $this->getSetting('format_type'),
-+ );
-+
-+ $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;
-+ }
-+
-+ /**
-+ * {@inheritdoc}
-+ */
-+ public function settingsSummary() {
-+ $summary = parent::settingsSummary();
-+
-+ if ($separator = $this->getSetting('separator')) {
-+ $summary[] = $this->t('Separator: %separator', ['%separator' => $separator]);
-+ }
-+
-+ return $summary;
-+ }
-+
-+ public function niceFormats() {
-+ $formats = [];
-+ $formats['nice_long'] = [
-+ 'label' => t('Nice long'),
-+ 'format' => 'F d, Y - h:i A',
-+ 'format_time_start' => 'F d, Y - h:i A',
-+ 'format_time_end' => 'h:i A',
-+ 'format_day_start' => 'F d',
-+ 'format_day_end' => 'd, Y',
-+ 'format_month_start' => 'F d',
-+ 'format_month_end' => 'F d, Y',
-+ 'format_year_start' => 'F d, Y',
-+ 'format_year_end' => 'F d, Y',
-+ ];
-+ $formats['nice_short'] = [
-+ 'label' => t('Nice short'),
-+ 'format' => 'm/d/Y - h:i a',
-+ 'format_time_start' => 'm/d/Y - h:i a',
-+ 'format_time_end' => 'h:i a',
-+ 'format_day_start' => 'm/d',
-+ 'format_day_end' => 'd/Y',
-+ 'format_month_start' => 'm/d',
-+ 'format_month_end' => 'm/d/Y',
-+ 'format_year_start' => 'm/d/Y',
-+ 'format_year_end' => 'm/d/Y',
-+ ];
-+ return $formats;
-+ }
-+
-+}
-diff --git a/src/Plugin/Field/FieldWidget/DateRangeNiceWidget.php b/src/Plugin/Field/FieldWidget/DateRangeNiceWidget.php
-new file mode 100644
-index 0000000..da74eb3
---- /dev/null
-+++ b/src/Plugin/Field/FieldWidget/DateRangeNiceWidget.php
-@@ -0,0 +1,101 @@
-+dateStorage = $date_storage;
-+ }
-+
-+ /**
-+ * {@inheritdoc}
-+ */
-+ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
-+ return new static(
-+ $plugin_id,
-+ $plugin_definition,
-+ $configuration['field_definition'],
-+ $configuration['settings'],
-+ $configuration['third_party_settings'],
-+ $container->get('entity_type.manager')->getStorage('date_format')
-+ );
-+ }
-+
-+ /**
-+ * {@inheritdoc}
-+ */
-+ public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
-+ $element = parent::formElement($items, $delta, $element, $form, $form_state);
-+
-+ // Identify the type of date and time elements to use.
-+ switch ($this->getFieldSetting('datetime_type')) {
-+ case DateRangeItem::DATETIME_TYPE_DATE:
-+ case DateRangeItem::DATETIME_TYPE_ALLDAY:
-+ $date_type = 'date';
-+ $time_type = 'none';
-+ $date_format = $this->dateStorage->load('html_date')->getPattern();
-+ $time_format = '';
-+ break;
-+
-+ default:
-+ $date_type = 'date';
-+ $time_type = 'time';
-+ $date_format = $this->dateStorage->load('html_date')->getPattern();
-+ $time_format = $this->dateStorage->load('html_time')->getPattern();
-+ break;
-+ }
-+
-+ $element['value'] += [
-+ '#date_date_format' => $date_format,
-+ '#date_date_element' => $date_type,
-+ '#date_date_callbacks' => [],
-+ '#date_time_format' => $time_format,
-+ '#date_time_element' => $time_type,
-+ '#date_time_callbacks' => [],
-+ ];
-+
-+ $element['end_value'] += [
-+ '#date_date_format' => $date_format,
-+ '#date_date_element' => $date_type,
-+ '#date_date_callbacks' => [],
-+ '#date_time_format' => $time_format,
-+ '#date_time_element' => $time_type,
-+ '#date_time_callbacks' => [],
-+ ];
-+
-+ return $element;
-+ }
-+
-+}
reverted:
--- b/modules/contrib/datetime_extras/config/install/datetime_extras.datetime_extras_range_format.medium.yml
+++ /dev/null
@@ -1,17 +0,0 @@
-langcode: en
-status: true
-dependencies: { }
-id: medium
-label: Medium
-date_settings:
- default_pattern: 'j F Y'
- separator: '–'
- same_month_start_pattern: j
- same_month_end_pattern: 'j F Y'
- same_year_start_pattern: 'j F'
- same_year_end_pattern: 'j F Y'
-datetime_settings:
- default_pattern: 'j F Y H:i'
- separator: '–'
- same_day_start_pattern: 'j F Y H:i'
- same_day_end_pattern: 'H:i'
reverted:
--- b/modules/contrib/datetime_extras/config/schema/datetime_extras.schema.yml
+++ /dev/null
@@ -1,58 +0,0 @@
-datetime_extras.datetime_extras_range_format.*:
- type: config_entity
- label: 'Date range format config'
- mapping:
- id:
- type: string
- label: 'ID'
- label:
- type: label
- label: 'Label'
-
- date_settings:
- type: mapping
- label: 'Date settings'
- mapping:
- default_pattern:
- type: string
- label: 'Default pattern'
- separator:
- type: string
- label: 'Separator'
- same_month_start_pattern:
- type: string
- label: 'Same month start pattern'
- same_month_end_pattern:
- type: string
- label: 'Same month end pattern'
- same_year_start_pattern:
- type: string
- label: 'Same year start pattern'
- same_year_end_pattern:
- type: string
- label: 'Same year end pattern'
-
- datetime_settings:
- type: mapping
- label: 'Datetime settings'
- mapping:
- default_pattern:
- type: string
- label: 'Default pattern'
- separator:
- type: string
- label: 'Separator'
- same_day_start_pattern:
- type: string
- label: 'Same day start pattern'
- same_day_end_pattern:
- type: string
- label: 'Same day end pattern'
-
-field.formatter.settings.datetime_extras:
- type: mapping
- label: 'Date/time range display format settings'
- mapping:
- format_type:
- type: string
- label: 'Date/time range format'
reverted:
--- b/modules/contrib/datetime_extras/datetime_extras.links.action.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-entity.datetime_extras_range_format.add_form:
- route_name: 'entity.datetime_extras_range_format.add_form'
- title: 'Add format'
- appears_on:
- - entity.datetime_extras_range_format.collection
reverted:
--- b/modules/contrib/datetime_extras/datetime_extras.links.menu.yml
+++ /dev/null
@@ -1,6 +0,0 @@
-entity.datetime_extras_range_format.collection:
- title: 'Date and time range formats'
- route_name: entity.datetime_extras_range_format.collection
- description: 'Configure how date and time ranges are displayed.'
- parent: system.admin_config_regional
- weight: 0
reverted:
--- b/modules/contrib/datetime_extras/datetime_extras.services.yml
+++ /dev/null
@@ -1,4 +0,0 @@
-services:
- datetime_extras.date_range.formatter:
- class: Drupal\datetime_extras\DateRangeFormatter
- arguments: ['@entity_type.manager', '@date.formatter']
reverted:
--- b/modules/contrib/datetime_extras/src/DateRangeFormatListBuilder.php
+++ /dev/null
@@ -1,151 +0,0 @@
-dateRangeFormatter = $date_range_formatter;
- }
-
- /**
- * {@inheritdoc}
- */
- public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
- return new static(
- $entity_type,
- $container->get('entity.manager')->getStorage($entity_type->id()),
- $container->get('datetime_extras.date_range.formatter')
- );
- }
-
- /**
- * {@inheritdoc}
- */
- public function buildHeader() {
- $header['label'] = $this->t('Name');
- $header['date'] = $this->t('Date examples');
- $header['datetime'] = $this->t('Date & time examples');
- return $header + parent::buildHeader();
- }
-
- /**
- * {@inheritdoc}
- */
- public function buildRow(EntityInterface $entity) {
- /** @var \Drupal\datetime_extras\Entity\DateRangeFormatInterface $format */
- $format = $entity;
-
- $row['label'] = $format->label();
- $row['date']['data'] = $this->dateExamples($format);
- $row['datetime']['data'] = $this->dateTimeExamples($format);
- return $row + parent::buildRow($entity);
- }
-
- /**
- * Examples of various date ranges shown using the given format.
- *
- * @param \Drupal\datetime_extras\Entity\DateRangeFormatInterface $format
- * The date range format entity.
- *
- * @return array
- * A render array suitable for use within the list builder table.
- */
- private function dateExamples(DateRangeFormatInterface $format) {
- $examples = [];
-
- // An example range that is a single day.
- $same_day_timestamp = \DateTime::createFromFormat('Y-m-d', '2017-01-01')->getTimestamp();
- $examples[] = $this->dateRangeFormatter->formatDateRange(
- $same_day_timestamp, $same_day_timestamp, $format->id());
-
- // An example range that spans several days within the same month.
- $same_month_start_timestamp = \DateTime::createFromFormat('Y-m-d', '2017-01-02')->getTimestamp();
- $same_month_end_timestamp = \DateTime::createFromFormat('Y-m-d', '2017-01-03')->getTimestamp();
- $examples[] = $this->dateRangeFormatter->formatDateRange(
- $same_month_start_timestamp, $same_month_end_timestamp, $format->id());
-
- // An example range that spans several months within the same year.
- $same_year_start_timestamp = \DateTime::createFromFormat('Y-m-d', '2017-01-04')->getTimestamp();
- $same_year_end_timestamp = \DateTime::createFromFormat('Y-m-d', '2017-02-05')->getTimestamp();
- $examples[] = $this->dateRangeFormatter->formatDateRange(
- $same_year_start_timestamp, $same_year_end_timestamp, $format->id());
-
- // An example range that spans multiple years.
- $fallback_start_timestamp = \DateTime::createFromFormat('Y-m-d', '2017-01-06')->getTimestamp();
- $fallback_end_timestamp = \DateTime::createFromFormat('Y-m-d', '2018-01-07')->getTimestamp();
- $examples[] = $this->dateRangeFormatter->formatDateRange(
- $fallback_start_timestamp, $fallback_end_timestamp, $format->id());
-
- $output = '';
- foreach ($examples as $example) {
- $output .= htmlspecialchars($example) . '
';
- }
- return ['#markup' => $output];
- }
-
- /**
- * Examples of various datetime ranges shown using the given format.
- *
- * @param \Drupal\datetime_extras\Entity\DateRangeFormatInterface $format
- * The date range format entity.
- *
- * @return array
- * A render array suitable for use within the list builder table.
- */
- private function dateTimeExamples(DateRangeFormatInterface $format) {
- $examples = [];
-
- // An example range that is a single date and time.
- $same_time_timestamp = \DateTime::createFromFormat('Y-m-d H:i', '2017-01-01 09:00')->getTimestamp();
- $examples[] = $this->dateRangeFormatter->formatDateTimeRange(
- $same_time_timestamp, $same_time_timestamp, $format->id());
-
- // An example range that is contained within a single day.
- $same_day_start_timestamp = \DateTime::createFromFormat('Y-m-d H:i', '2017-01-01 09:00')->getTimestamp();
- $same_day_end_timestamp = \DateTime::createFromFormat('Y-m-d H:i', '2017-01-01 13:00')->getTimestamp();
- $examples[] = $this->dateRangeFormatter->formatDateTimeRange(
- $same_day_start_timestamp, $same_day_end_timestamp, $format->id());
-
- // An example range that spans multiple days.
- $fallback_start_timestamp = \DateTime::createFromFormat('Y-m-d H:i', '2017-01-01 09:00')->getTimestamp();
- $fallback_end_timestamp = \DateTime::createFromFormat('Y-m-d H:i', '2017-01-02 13:00')->getTimestamp();
- $examples[] = $this->dateRangeFormatter->formatDateTimeRange(
- $fallback_start_timestamp, $fallback_end_timestamp, $format->id());
-
- $output = '';
- foreach ($examples as $example) {
- $output .= htmlspecialchars($example) . '
';
- }
- return ['#markup' => $output];
- }
-
-}
reverted:
--- b/modules/contrib/datetime_extras/src/DateRangeFormatter.php
+++ /dev/null
@@ -1,135 +0,0 @@
-dateRangeFormatStorage = $entity_type_manager->getStorage('datetime_extras_range_format');
- $this->dateFormatter = $date_formatter;
- }
-
- /**
- * {@inheritdoc}
- */
- public function formatDateRange($start_timestamp, $end_timestamp, $type = 'medium', $timezone = NULL, $langcode = NULL) {
- $start_date_time = DrupalDateTime::createFromTimestamp($start_timestamp, $timezone);
- $end_date_time = DrupalDateTime::createFromTimestamp($end_timestamp, $timezone);
-
- /** @var \Drupal\datetime_extras\Entity\DateRangeFormatInterface $entity */
- $entity = $this->dateRangeFormatStorage->load($type);
- $date_settings = $entity->getDateSettings();
- $default_pattern = $date_settings['default_pattern'];
- $separator = $date_settings['separator'] ?: '';
-
- // Strings containing the ISO-8601 representations of the start and end
- // date can be used to determine if the day, month or year is the same.
- $start_iso_8601 = $start_date_time->format('Y-m-d');
- $end_iso_8601 = $end_date_time->format('Y-m-d');
-
- if ($start_iso_8601 === $end_iso_8601) {
- // The range is a single day.
- return $this->dateFormatter->format($start_timestamp, 'custom',
- $default_pattern, $timezone, $langcode);
- }
- elseif (substr($start_iso_8601, 0, 7) === substr($end_iso_8601, 0, 7)) {
- // The range spans several days within the same month.
- $start_pattern = isset($date_settings['same_month_start_pattern']) ? $date_settings['same_month_start_pattern'] : '';
- $end_pattern = isset($date_settings['same_month_end_pattern']) ? $date_settings['same_month_end_pattern'] : '';
- if ($start_pattern && $end_pattern) {
- $start_text = $this->dateFormatter->format($start_timestamp, 'custom', $start_pattern, $timezone, $langcode);
- $end_text = $this->dateFormatter->format($end_timestamp, 'custom', $end_pattern, $timezone, $langcode);
- return $start_text . $separator . $end_text;
- }
- }
- elseif (substr($start_iso_8601, 0, 4) === substr($end_iso_8601, 0, 4)) {
- // The range spans several months within the same year.
- $start_pattern = isset($date_settings['same_year_start_pattern']) ? $date_settings['same_year_start_pattern'] : '';
- $end_pattern = isset($date_settings['same_year_end_pattern']) ? $date_settings['same_year_end_pattern'] : '';
- if ($start_pattern && $end_pattern) {
- $start_text = $this->dateFormatter->format($start_timestamp, 'custom', $start_pattern, $timezone, $langcode);
- $end_text = $this->dateFormatter->format($end_timestamp, 'custom', $end_pattern, $timezone, $langcode);
- return $start_text . $separator . $end_text;
- }
- }
-
- // Fallback: show the start and end dates in full using the default
- // pattern. This is the case if the range spans different years,
- // or if the other patterns are not specified.
- $start_text = $this->dateFormatter->format($start_timestamp, 'custom', $default_pattern, $timezone, $langcode);
- $end_text = $this->dateFormatter->format($end_timestamp, 'custom', $default_pattern, $timezone, $langcode);
- return $start_text . $separator . $end_text;
- }
-
- /**
- * {@inheritdoc}
- */
- public function formatDateTimeRange($start_timestamp, $end_timestamp, $type = 'medium', $timezone = NULL, $langcode = NULL) {
- $start_date_time = DrupalDateTime::createFromTimestamp($start_timestamp, $timezone);
- $end_date_time = DrupalDateTime::createFromTimestamp($end_timestamp, $timezone);
-
- /** @var \Drupal\datetime_extras\Entity\DateRangeFormatInterface $entity */
- $entity = $this->dateRangeFormatStorage->load($type);
- $datetime_settings = $entity->getDateTimeSettings();
- $default_pattern = $datetime_settings['default_pattern'];
- $separator = $datetime_settings['separator'] ?: '';
-
- // Strings containing the ISO-8601 representations of the start and end
- // datetime can be used to determine if the date and/or time are the same.
- $start_iso_8601 = $start_date_time->format('Y-m-d\TH:i:s');
- $end_iso_8601 = $end_date_time->format('Y-m-d\TH:i:s');
-
- if ($start_iso_8601 === $end_iso_8601) {
- // The range is a single date and time.
- return $this->dateFormatter->format($start_timestamp, 'custom',
- $default_pattern, $timezone, $langcode);
- }
- elseif (substr($start_iso_8601, 0, 10) == substr($end_iso_8601, 0, 10)) {
- // The range is contained within a single day.
- $start_pattern = isset($datetime_settings['same_day_start_pattern']) ? $datetime_settings['same_day_start_pattern'] : '';
- $end_pattern = isset($datetime_settings['same_day_end_pattern']) ? $datetime_settings['same_day_end_pattern'] : '';
- if ($start_pattern && $end_pattern) {
- $start_text = $this->dateFormatter->format($start_timestamp, 'custom', $start_pattern, $timezone, $langcode);
- $end_text = $this->dateFormatter->format($end_timestamp, 'custom', $end_pattern, $timezone, $langcode);
- return $start_text . $separator . $end_text;
- }
- }
-
- // Fallback: show the start and end datetimes in full using the default
- // pattern. This is the case if the range spans different days,
- // or if the other patterns are not specified.
- $start_text = $this->dateFormatter->format($start_timestamp, 'custom', $default_pattern, $timezone, $langcode);
- $end_text = $this->dateFormatter->format($end_timestamp, 'custom', $default_pattern, $timezone, $langcode);
- return $start_text . $separator . $end_text;
- }
-
-}
reverted:
--- b/modules/contrib/datetime_extras/src/DateRangeFormatterInterface.php
+++ /dev/null
@@ -1,66 +0,0 @@
-get('date_settings');
- }
-
- /**
- * {@inheritdoc}
- */
- public function getDateTimeSettings() {
- return $this->get('datetime_settings');
- }
-
- /**
- * {@inheritdoc}
- */
- public function getCacheTagsToInvalidate() {
- return ['rendered'];
- }
-
-}
reverted:
--- b/modules/contrib/datetime_extras/src/Entity/DateRangeFormatInterface.php
+++ /dev/null
@@ -1,46 +0,0 @@
-t('Are you sure you want to delete the date range format %name?', ['%name' => $this->entity->label()]);
- }
-
-}
reverted:
--- b/modules/contrib/datetime_extras/src/Form/DateRangeFormatForm.php
+++ /dev/null
@@ -1,223 +0,0 @@
-entity;
-
- $form['label'] = [
- '#type' => 'textfield',
- '#title' => $this->t('Label'),
- '#maxlength' => 255,
- '#default_value' => $format->label(),
- '#description' => $this->t("Name of the date time range format."),
- '#required' => TRUE,
- ];
-
- $form['id'] = [
- '#type' => 'machine_name',
- '#default_value' => $format->id(),
- '#machine_name' => [
- 'exists' => '\Drupal\datetime_extras\Entity\DateRangeFormat::load',
- ],
- '#disabled' => !$format->isNew(),
- ];
-
- $date_settings = $format->getDateSettings();
-
- $form['date'] = [
- '#type' => 'vertical_tabs',
- '#title' => $this->t('Date only formats'),
- '#tree' => FALSE,
- ];
-
- $form['date']['basic'] = [
- '#type' => 'details',
- '#title' => $this->t('Basic'),
- '#open' => TRUE,
- '#weight' => 1,
- '#group' => 'date',
- '#description' => $this->t('Basic date format used for single dates, or ranges that cannot be shown in a compact form.'),
- ];
-
- $form['date']['basic']['default_pattern'] = [
- '#type' => 'textfield',
- '#title' => $this->t('Pattern'),
- '#default_value' => $date_settings['default_pattern'] ?: '',
- '#maxlength' => 100,
- '#description' => $this->t('A user-defined date format. See the PHP manual for available options.'),
- '#required' => TRUE,
- '#parents' => ['date_settings', 'default_pattern'],
- ];
-
- $form['date']['basic']['separator'] = [
- '#type' => 'textfield',
- '#title' => $this->t('Separator'),
- '#default_value' => $date_settings['separator'] ?: '',
- '#maxlength' => 100,
- '#size' => 10,
- '#description' => $this->t('Text between start and end dates.'),
- '#required' => FALSE,
- '#parents' => ['date_settings', 'separator'],
- ];
-
- $form['date']['same_month'] = [
- '#type' => 'details',
- '#title' => $this->t('Same month'),
- '#open' => TRUE,
- '#weight' => 2,
- '#group' => 'date',
- '#description' => $this->t('Optional formatting of date ranges that span multiple days within the same month.'),
- ];
-
- $form['date']['same_month']['same_month_start_pattern'] = [
- '#type' => 'textfield',
- '#title' => $this->t('Start date pattern'),
- '#default_value' => $date_settings['same_month_start_pattern'] ?: '',
- '#maxlength' => 100,
- '#description' => $this->t('A user-defined date format. See the PHP manual for available options.'),
- '#parents' => ['date_settings', 'same_month_start_pattern'],
- ];
-
- $form['date']['same_month']['same_month_end_pattern'] = [
- '#type' => 'textfield',
- '#title' => $this->t('End date pattern'),
- '#default_value' => $date_settings['same_month_end_pattern'] ?: '',
- '#maxlength' => 100,
- '#description' => $this->t('A user-defined date format. See the PHP manual for available options.'),
- '#parents' => ['date_settings', 'same_month_end_pattern'],
- ];
-
- $form['date']['same_year'] = [
- '#type' => 'details',
- '#title' => $this->t('Same year'),
- '#open' => TRUE,
- '#weight' => 2,
- '#group' => 'date',
- '#description' => $this->t('Optional formatting of date ranges that span multiple months within the same year.'),
- ];
-
- $form['date']['same_year']['same_year_start_pattern'] = [
- '#type' => 'textfield',
- '#title' => $this->t('Start date pattern'),
- '#default_value' => $date_settings['same_year_start_pattern'] ?: '',
- '#maxlength' => 100,
- '#description' => $this->t('A user-defined date format. See the PHP manual for available options.'),
- '#parents' => ['date_settings', 'same_year_start_pattern'],
- ];
-
- $form['date']['same_year']['same_year_end_pattern'] = [
- '#type' => 'textfield',
- '#title' => $this->t('End date pattern'),
- '#default_value' => $date_settings['same_year_end_pattern'] ?: '',
- '#maxlength' => 100,
- '#description' => $this->t('A user-defined date format. See the PHP manual for available options.'),
- '#parents' => ['date_settings', 'same_year_end_pattern'],
- ];
-
- $datetime_settings = $format->getDateTimeSettings();
-
- $form['datetime'] = [
- '#type' => 'vertical_tabs',
- '#title' => $this->t('Date & time formats'),
- ];
-
- $form['datetime']['basic'] = [
- '#type' => 'details',
- '#title' => $this->t('Basic'),
- '#open' => TRUE,
- '#weight' => 1,
- '#group' => 'datetime',
- '#description' => $this->t('Basic date and time format used for single date/times, or ranges that cannot be shown in a compact form.'),
- ];
-
- $form['datetime']['basic']['default_pattern'] = [
- '#type' => 'textfield',
- '#title' => $this->t('Pattern'),
- '#default_value' => $datetime_settings['default_pattern'] ?: '',
- '#maxlength' => 100,
- '#description' => $this->t('A user-defined date format. See the PHP manual for available options.'),
- '#required' => TRUE,
- '#parents' => ['datetime_settings', 'default_pattern'],
- ];
-
- $form['datetime']['basic']['separator'] = [
- '#type' => 'textfield',
- '#title' => $this->t('Separator'),
- '#default_value' => $datetime_settings['separator'] ?: '',
- '#maxlength' => 100,
- '#size' => 10,
- '#description' => $this->t('Text between start and end date/times.'),
- '#required' => FALSE,
- '#parents' => ['datetime_settings', 'separator'],
- ];
-
- $form['datetime']['same_day'] = [
- '#type' => 'details',
- '#title' => $this->t('Same day'),
- '#open' => TRUE,
- '#weight' => 2,
- '#group' => 'datetime',
- '#description' => $this->t('Optional formatting of time ranges within a single day.'),
- ];
-
- $form['datetime']['same_day']['same_day_start_pattern'] = [
- '#type' => 'textfield',
- '#title' => $this->t('Start date/time pattern'),
- '#default_value' => $datetime_settings['same_day_start_pattern'] ?: '',
- '#maxlength' => 100,
- '#description' => $this->t('A user-defined date format. See the PHP manual for available options.'),
- '#parents' => ['datetime_settings', 'same_day_start_pattern'],
- ];
-
- $form['datetime']['same_day']['same_day_end_pattern'] = [
- '#type' => 'textfield',
- '#title' => $this->t('End date/time pattern'),
- '#default_value' => $datetime_settings['same_day_end_pattern'] ?: '',
- '#maxlength' => 100,
- '#description' => $this->t('A user-defined date format. See the PHP manual for available options.'),
- '#parents' => ['datetime_settings', 'same_day_end_pattern'],
- ];
-
- return $form;
- }
-
- /**
- * {@inheritdoc}
- */
- public function save(array $form, FormStateInterface $form_state) {
- $date_range_format = $this->entity;
- $status = $date_range_format->save();
-
- switch ($status) {
- case SAVED_NEW:
- drupal_set_message($this->t('Created the %label date range format.', [
- '%label' => $date_range_format->label(),
- ]));
- break;
-
- default:
- drupal_set_message($this->t('Updated the %label date range format.', [
- '%label' => $date_range_format->label(),
- ]));
- }
- $form_state->setRedirectUrl($date_range_format->toUrl('collection'));
- }
-
-}
reverted:
--- b/modules/contrib/datetime_extras/src/Plugin/Field/FieldFormatter/DateRangeCompactFormatter.php
+++ /dev/null
@@ -1,168 +0,0 @@
- elements, with
- * configurable date formats (from the list of configured formats) and a
- * separator.
- *
- * @FieldFormatter(
- * id = "datetime_extras",
- * label = @Translation("Datetime Format"),
- * field_types = {
- * "daterange"
- * }
- * )
- */
-class DateRangeCompactFormatter extends FormatterBase implements ContainerFactoryPluginInterface {
-
- /**
- * The date range formatter service.
- *
- * @var \Drupal\datetime_extras\DateRangeFormatterInterface
- */
- protected $dateRangeFormatter;
-
- /**
- * The date range format entity storage.
- *
- * @var \Drupal\Core\Entity\EntityStorageInterface
- */
- protected $dateRangeFormatStorage;
-
- /**
- * Constructs a new DateRangeCompactFormatter.
- *
- * @param string $plugin_id
- * The plugin_id for the formatter.
- * @param mixed $plugin_definition
- * The plugin implementation definition.
- * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
- * The definition of the field to which the formatter is associated.
- * @param array $settings
- * The formatter settings.
- * @param string $label
- * The formatter label display setting.
- * @param string $view_mode
- * The view mode.
- * @param array $third_party_settings
- * Third party settings.
- * @param \Drupal\datetime_extras\DateRangeFormatterInterface $date_range_formatter
- * The date formatter service.
- * @param \Drupal\Core\Entity\EntityStorageInterface $date_range_format_storage
- * The date format entity storage.
- */
- public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, DateRangeFormatterInterface $date_range_formatter, EntityStorageInterface $date_range_format_storage) {
- parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
-
- $this->dateRangeFormatter = $date_range_formatter;
- $this->dateRangeFormatStorage = $date_range_format_storage;
- }
-
- /**
- * {@inheritdoc}
- */
- public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
- return new static(
- $plugin_id,
- $plugin_definition,
- $configuration['field_definition'],
- $configuration['settings'],
- $configuration['label'],
- $configuration['view_mode'],
- $configuration['third_party_settings'],
- $container->get('datetime_extras.date_range.formatter'),
- $container->get('entity_type.manager')->getStorage('datetime_extras_range_format')
- );
- }
-
- /**
- * {@inheritdoc}
- */
- public static function defaultSettings() {
- return [
- 'format_type' => 'medium',
- ] + parent::defaultSettings();
- }
-
- /**
- * {@inheritdoc}
- */
- public function settingsForm(array $form, FormStateInterface $form_state) {
- $form = parent::settingsForm($form, $form_state);
-
- $format_types = $this->dateRangeFormatStorage->loadMultiple();
- $options = [];
- foreach ($format_types as $type => $type_info) {
- $options[$type] = $type_info->label();
- }
-
- $form['format_type'] = [
- '#type' => 'select',
- '#title' => $this->t('Date and time range format'),
- '#description' => $this->t("Choose a format for displaying the date and time range."),
- '#options' => $options,
- '#default_value' => $this->getSetting('format_type'),
- ];
-
- return $form;
- }
-
- /**
- * {@inheritdoc}
- */
- public function settingsSummary() {
- $summary = parent::settingsSummary();
- $summary[] = $this->t('Format: @format', ['@format' => $this->getSetting('format_type')]);
- return $summary;
- }
-
- /**
- * {@inheritdoc}
- */
- public function viewElements(FieldItemListInterface $items, $langcode) {
- $elements = [];
-
- foreach ($items as $delta => $item) {
- if (!empty($item->start_date) && !empty($item->end_date)) {
- $start_timestamp = $item->start_date->getTimestamp();
- $end_timestamp = $item->end_date->getTimestamp();
- $format = $this->getSetting('format_type');
-
- if ($this->getFieldSetting('datetime_type') == DateTimeItem::DATETIME_TYPE_DATE) {
- $timezone = DATETIME_STORAGE_TIMEZONE;
- $text = $this->dateRangeFormatter->formatDateRange($start_timestamp, $end_timestamp, $format, $timezone);
- }
- else {
- $timezone = drupal_get_user_timezone();
- $text = $this->dateRangeFormatter->formatDateTimeRange($start_timestamp, $end_timestamp, $format, $timezone);
- }
-
- $elements[$delta] = [
- '#plain_text' => $text,
- '#cache' => [
- 'contexts' => [
- 'timezone',
- ],
- ],
- ];
- }
- }
-
- return $elements;
- }
-
-}
only in patch2:
unchanged:
--- /dev/null
+++ b/modules/contrib/datetime_extras/modules/datetime_extras_daterange/config/install/datetime_extras_daterange.daterange_range_format.medium.yml
@@ -0,0 +1,17 @@
+langcode: en
+status: true
+dependencies: { }
+id: medium
+label: Medium
+date_settings:
+ default_pattern: 'j F Y'
+ separator: '–'
+ same_month_start_pattern: j
+ same_month_end_pattern: 'j F Y'
+ same_year_start_pattern: 'j F'
+ same_year_end_pattern: 'j F Y'
+datetime_settings:
+ default_pattern: 'j F Y H:i'
+ separator: '–'
+ same_day_start_pattern: 'j F Y H:i'
+ same_day_end_pattern: 'H:i'
only in patch2:
unchanged:
--- /dev/null
+++ b/modules/contrib/datetime_extras/modules/datetime_extras_daterange/config/schema/datetime_extras_daterange.schema.yml
@@ -0,0 +1,58 @@
+datetime_extras_daterange.daterange_range_format.*:
+ type: config_entity
+ label: 'Date range format config'
+ mapping:
+ id:
+ type: string
+ label: 'ID'
+ label:
+ type: label
+ label: 'Label'
+
+ date_settings:
+ type: mapping
+ label: 'Date settings'
+ mapping:
+ default_pattern:
+ type: string
+ label: 'Default pattern'
+ separator:
+ type: string
+ label: 'Separator'
+ same_month_start_pattern:
+ type: string
+ label: 'Same month start pattern'
+ same_month_end_pattern:
+ type: string
+ label: 'Same month end pattern'
+ same_year_start_pattern:
+ type: string
+ label: 'Same year start pattern'
+ same_year_end_pattern:
+ type: string
+ label: 'Same year end pattern'
+
+ datetime_settings:
+ type: mapping
+ label: 'Datetime settings'
+ mapping:
+ default_pattern:
+ type: string
+ label: 'Default pattern'
+ separator:
+ type: string
+ label: 'Separator'
+ same_day_start_pattern:
+ type: string
+ label: 'Same day start pattern'
+ same_day_end_pattern:
+ type: string
+ label: 'Same day end pattern'
+
+field.formatter.settings.datetime_extras_daterange:
+ type: mapping
+ label: 'Date/time range display format settings'
+ mapping:
+ format_type:
+ type: string
+ label: 'Date/time range format'
only in patch2:
unchanged:
--- /dev/null
+++ b/modules/contrib/datetime_extras/modules/datetime_extras_daterange/datetime_extras_daterange.info.yml
@@ -0,0 +1,6 @@
+name: 'Date Range Formatter'
+type: module
+description: 'Provides a compact formatter for date range fields.'
+core: 8.x
+dependencies:
+ - drupal:datetime_range
only in patch2:
unchanged:
--- /dev/null
+++ b/modules/contrib/datetime_extras/modules/datetime_extras_daterange/datetime_extras_daterange.links.action.yml
@@ -0,0 +1,5 @@
+entity.daterange_range_format.add_form:
+ route_name: 'entity.daterange_range_format.add_form'
+ title: 'Add format'
+ appears_on:
+ - entity.daterange_range_format.collection
only in patch2:
unchanged:
--- /dev/null
+++ b/modules/contrib/datetime_extras/modules/datetime_extras_daterange/datetime_extras_daterange.links.menu.yml
@@ -0,0 +1,6 @@
+entity.daterange_range_format.collection:
+ title: 'Daterange formats'
+ route_name: entity.daterange_range_format.collection
+ description: 'Configure how date and time ranges are displayed.'
+ parent: system.admin_config_regional
+ weight: 0
only in patch2:
unchanged:
--- /dev/null
+++ b/modules/contrib/datetime_extras/modules/datetime_extras_daterange/datetime_extras_daterange.services.yml
@@ -0,0 +1,4 @@
+services:
+ datetime_extras_daterange.date_range.formatter:
+ class: Drupal\datetime_extras_daterange\DateRangeFormatter
+ arguments: ['@entity_type.manager', '@date.formatter']
only in patch2:
unchanged:
--- /dev/null
+++ b/modules/contrib/datetime_extras/modules/datetime_extras_daterange/src/DateRangeFormatListBuilder.php
@@ -0,0 +1,151 @@
+dateRangeFormatter = $date_range_formatter;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
+ return new static(
+ $entity_type,
+ $container->get('entity.manager')->getStorage($entity_type->id()),
+ $container->get('datetime_extras_daterange.date_range.formatter')
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function buildHeader() {
+ $header['label'] = $this->t('Name');
+ $header['date'] = $this->t('Date examples');
+ $header['datetime'] = $this->t('Date & time examples');
+ return $header + parent::buildHeader();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function buildRow(EntityInterface $entity) {
+ /** @var \Drupal\datetime_extras_daterange\Entity\DateRangeFormatInterface $format */
+ $format = $entity;
+
+ $row['label'] = $format->label();
+ $row['date']['data'] = $this->dateExamples($format);
+ $row['datetime']['data'] = $this->dateTimeExamples($format);
+ return $row + parent::buildRow($entity);
+ }
+
+ /**
+ * Examples of various date ranges shown using the given format.
+ *
+ * @param \Drupal\datetime_extras_daterange\Entity\DateRangeFormatInterface $format
+ * The date range format entity.
+ *
+ * @return array
+ * A render array suitable for use within the list builder table.
+ */
+ private function dateExamples(DateRangeFormatInterface $format) {
+ $examples = [];
+
+ // An example range that is a single day.
+ $same_day_timestamp = \DateTime::createFromFormat('Y-m-d', '2017-01-01')->getTimestamp();
+ $examples[] = $this->dateRangeFormatter->formatDateRange(
+ $same_day_timestamp, $same_day_timestamp, $format->id());
+
+ // An example range that spans several days within the same month.
+ $same_month_start_timestamp = \DateTime::createFromFormat('Y-m-d', '2017-01-02')->getTimestamp();
+ $same_month_end_timestamp = \DateTime::createFromFormat('Y-m-d', '2017-01-03')->getTimestamp();
+ $examples[] = $this->dateRangeFormatter->formatDateRange(
+ $same_month_start_timestamp, $same_month_end_timestamp, $format->id());
+
+ // An example range that spans several months within the same year.
+ $same_year_start_timestamp = \DateTime::createFromFormat('Y-m-d', '2017-01-04')->getTimestamp();
+ $same_year_end_timestamp = \DateTime::createFromFormat('Y-m-d', '2017-02-05')->getTimestamp();
+ $examples[] = $this->dateRangeFormatter->formatDateRange(
+ $same_year_start_timestamp, $same_year_end_timestamp, $format->id());
+
+ // An example range that spans multiple years.
+ $fallback_start_timestamp = \DateTime::createFromFormat('Y-m-d', '2017-01-06')->getTimestamp();
+ $fallback_end_timestamp = \DateTime::createFromFormat('Y-m-d', '2018-01-07')->getTimestamp();
+ $examples[] = $this->dateRangeFormatter->formatDateRange(
+ $fallback_start_timestamp, $fallback_end_timestamp, $format->id());
+
+ $output = '';
+ foreach ($examples as $example) {
+ $output .= htmlspecialchars($example) . '
';
+ }
+ return ['#markup' => $output];
+ }
+
+ /**
+ * Examples of various datetime ranges shown using the given format.
+ *
+ * @param \Drupal\datetime_extras_daterange\Entity\DateRangeFormatInterface $format
+ * The date range format entity.
+ *
+ * @return array
+ * A render array suitable for use within the list builder table.
+ */
+ private function dateTimeExamples(DateRangeFormatInterface $format) {
+ $examples = [];
+
+ // An example range that is a single date and time.
+ $same_time_timestamp = \DateTime::createFromFormat('Y-m-d H:i', '2017-01-01 09:00')->getTimestamp();
+ $examples[] = $this->dateRangeFormatter->formatDateTimeRange(
+ $same_time_timestamp, $same_time_timestamp, $format->id());
+
+ // An example range that is contained within a single day.
+ $same_day_start_timestamp = \DateTime::createFromFormat('Y-m-d H:i', '2017-01-01 09:00')->getTimestamp();
+ $same_day_end_timestamp = \DateTime::createFromFormat('Y-m-d H:i', '2017-01-01 13:00')->getTimestamp();
+ $examples[] = $this->dateRangeFormatter->formatDateTimeRange(
+ $same_day_start_timestamp, $same_day_end_timestamp, $format->id());
+
+ // An example range that spans multiple days.
+ $fallback_start_timestamp = \DateTime::createFromFormat('Y-m-d H:i', '2017-01-01 09:00')->getTimestamp();
+ $fallback_end_timestamp = \DateTime::createFromFormat('Y-m-d H:i', '2017-01-02 13:00')->getTimestamp();
+ $examples[] = $this->dateRangeFormatter->formatDateTimeRange(
+ $fallback_start_timestamp, $fallback_end_timestamp, $format->id());
+
+ $output = '';
+ foreach ($examples as $example) {
+ $output .= htmlspecialchars($example) . '
';
+ }
+ return ['#markup' => $output];
+ }
+
+}
only in patch2:
unchanged:
--- /dev/null
+++ b/modules/contrib/datetime_extras/modules/datetime_extras_daterange/src/DateRangeFormatter.php
@@ -0,0 +1,135 @@
+dateRangeFormatStorage = $entity_type_manager->getStorage('daterange_range_format');
+ $this->dateFormatter = $date_formatter;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function formatDateRange($start_timestamp, $end_timestamp, $type = 'medium', $timezone = NULL, $langcode = NULL) {
+ $start_date_time = DrupalDateTime::createFromTimestamp($start_timestamp, $timezone);
+ $end_date_time = DrupalDateTime::createFromTimestamp($end_timestamp, $timezone);
+
+ /** @var \Drupal\datetime_extras_daterange\Entity\DateRangeFormatInterface $entity */
+ $entity = $this->dateRangeFormatStorage->load($type);
+ $date_settings = $entity->getDateSettings();
+ $default_pattern = $date_settings['default_pattern'];
+ $separator = $date_settings['separator'] ?: '';
+
+ // Strings containing the ISO-8601 representations of the start and end
+ // date can be used to determine if the day, month or year is the same.
+ $start_iso_8601 = $start_date_time->format('Y-m-d');
+ $end_iso_8601 = $end_date_time->format('Y-m-d');
+
+ if ($start_iso_8601 === $end_iso_8601) {
+ // The range is a single day.
+ return $this->dateFormatter->format($start_timestamp, 'custom',
+ $default_pattern, $timezone, $langcode);
+ }
+ elseif (substr($start_iso_8601, 0, 7) === substr($end_iso_8601, 0, 7)) {
+ // The range spans several days within the same month.
+ $start_pattern = isset($date_settings['same_month_start_pattern']) ? $date_settings['same_month_start_pattern'] : '';
+ $end_pattern = isset($date_settings['same_month_end_pattern']) ? $date_settings['same_month_end_pattern'] : '';
+ if ($start_pattern && $end_pattern) {
+ $start_text = $this->dateFormatter->format($start_timestamp, 'custom', $start_pattern, $timezone, $langcode);
+ $end_text = $this->dateFormatter->format($end_timestamp, 'custom', $end_pattern, $timezone, $langcode);
+ return $start_text . $separator . $end_text;
+ }
+ }
+ elseif (substr($start_iso_8601, 0, 4) === substr($end_iso_8601, 0, 4)) {
+ // The range spans several months within the same year.
+ $start_pattern = isset($date_settings['same_year_start_pattern']) ? $date_settings['same_year_start_pattern'] : '';
+ $end_pattern = isset($date_settings['same_year_end_pattern']) ? $date_settings['same_year_end_pattern'] : '';
+ if ($start_pattern && $end_pattern) {
+ $start_text = $this->dateFormatter->format($start_timestamp, 'custom', $start_pattern, $timezone, $langcode);
+ $end_text = $this->dateFormatter->format($end_timestamp, 'custom', $end_pattern, $timezone, $langcode);
+ return $start_text . $separator . $end_text;
+ }
+ }
+
+ // Fallback: show the start and end dates in full using the default
+ // pattern. This is the case if the range spans different years,
+ // or if the other patterns are not specified.
+ $start_text = $this->dateFormatter->format($start_timestamp, 'custom', $default_pattern, $timezone, $langcode);
+ $end_text = $this->dateFormatter->format($end_timestamp, 'custom', $default_pattern, $timezone, $langcode);
+ return $start_text . $separator . $end_text;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function formatDateTimeRange($start_timestamp, $end_timestamp, $type = 'medium', $timezone = NULL, $langcode = NULL) {
+ $start_date_time = DrupalDateTime::createFromTimestamp($start_timestamp, $timezone);
+ $end_date_time = DrupalDateTime::createFromTimestamp($end_timestamp, $timezone);
+
+ /** @var \Drupal\datetime_extras_daterange\Entity\DateRangeFormatInterface $entity */
+ $entity = $this->dateRangeFormatStorage->load($type);
+ $datetime_settings = $entity->getDateTimeSettings();
+ $default_pattern = $datetime_settings['default_pattern'];
+ $separator = $datetime_settings['separator'] ?: '';
+
+ // Strings containing the ISO-8601 representations of the start and end
+ // datetime can be used to determine if the date and/or time are the same.
+ $start_iso_8601 = $start_date_time->format('Y-m-d\TH:i:s');
+ $end_iso_8601 = $end_date_time->format('Y-m-d\TH:i:s');
+
+ if ($start_iso_8601 === $end_iso_8601) {
+ // The range is a single date and time.
+ return $this->dateFormatter->format($start_timestamp, 'custom',
+ $default_pattern, $timezone, $langcode);
+ }
+ elseif (substr($start_iso_8601, 0, 10) == substr($end_iso_8601, 0, 10)) {
+ // The range is contained within a single day.
+ $start_pattern = isset($datetime_settings['same_day_start_pattern']) ? $datetime_settings['same_day_start_pattern'] : '';
+ $end_pattern = isset($datetime_settings['same_day_end_pattern']) ? $datetime_settings['same_day_end_pattern'] : '';
+ if ($start_pattern && $end_pattern) {
+ $start_text = $this->dateFormatter->format($start_timestamp, 'custom', $start_pattern, $timezone, $langcode);
+ $end_text = $this->dateFormatter->format($end_timestamp, 'custom', $end_pattern, $timezone, $langcode);
+ return $start_text . $separator . $end_text;
+ }
+ }
+
+ // Fallback: show the start and end datetimes in full using the default
+ // pattern. This is the case if the range spans different days,
+ // or if the other patterns are not specified.
+ $start_text = $this->dateFormatter->format($start_timestamp, 'custom', $default_pattern, $timezone, $langcode);
+ $end_text = $this->dateFormatter->format($end_timestamp, 'custom', $default_pattern, $timezone, $langcode);
+ return $start_text . $separator . $end_text;
+ }
+
+}
only in patch2:
unchanged:
--- /dev/null
+++ b/modules/contrib/datetime_extras/modules/datetime_extras_daterange/src/DateRangeFormatterInterface.php
@@ -0,0 +1,66 @@
+get('date_settings');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getDateTimeSettings() {
+ return $this->get('datetime_settings');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getCacheTagsToInvalidate() {
+ return ['rendered'];
+ }
+
+}
only in patch2:
unchanged:
--- /dev/null
+++ b/modules/contrib/datetime_extras/modules/datetime_extras_daterange/src/Entity/DateRangeFormatInterface.php
@@ -0,0 +1,46 @@
+t('Are you sure you want to delete the date range format %name?', ['%name' => $this->entity->label()]);
+ }
+
+}
only in patch2:
unchanged:
--- /dev/null
+++ b/modules/contrib/datetime_extras/modules/datetime_extras_daterange/src/Form/DateRangeFormatForm.php
@@ -0,0 +1,223 @@
+entity;
+
+ $form['label'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Label'),
+ '#maxlength' => 255,
+ '#default_value' => $format->label(),
+ '#description' => $this->t("Name of the date time range format."),
+ '#required' => TRUE,
+ ];
+
+ $form['id'] = [
+ '#type' => 'machine_name',
+ '#default_value' => $format->id(),
+ '#machine_name' => [
+ 'exists' => '\Drupal\datetime_extras_daterange\Entity\DateRangeFormat::load',
+ ],
+ '#disabled' => !$format->isNew(),
+ ];
+
+ $date_settings = $format->getDateSettings();
+
+ $form['date'] = [
+ '#type' => 'vertical_tabs',
+ '#title' => $this->t('Date only formats'),
+ '#tree' => FALSE,
+ ];
+
+ $form['date']['basic'] = [
+ '#type' => 'details',
+ '#title' => $this->t('Basic'),
+ '#open' => TRUE,
+ '#weight' => 1,
+ '#group' => 'date',
+ '#description' => $this->t('Basic date format used for single dates, or ranges that cannot be shown in a compact form.'),
+ ];
+
+ $form['date']['basic']['default_pattern'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Pattern'),
+ '#default_value' => $date_settings['default_pattern'] ?: '',
+ '#maxlength' => 100,
+ '#description' => $this->t('A user-defined date format. See the PHP manual for available options.'),
+ '#required' => TRUE,
+ '#parents' => ['date_settings', 'default_pattern'],
+ ];
+
+ $form['date']['basic']['separator'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Separator'),
+ '#default_value' => $date_settings['separator'] ?: '',
+ '#maxlength' => 100,
+ '#size' => 10,
+ '#description' => $this->t('Text between start and end dates.'),
+ '#required' => FALSE,
+ '#parents' => ['date_settings', 'separator'],
+ ];
+
+ $form['date']['same_month'] = [
+ '#type' => 'details',
+ '#title' => $this->t('Same month'),
+ '#open' => TRUE,
+ '#weight' => 2,
+ '#group' => 'date',
+ '#description' => $this->t('Optional formatting of date ranges that span multiple days within the same month.'),
+ ];
+
+ $form['date']['same_month']['same_month_start_pattern'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Start date pattern'),
+ '#default_value' => $date_settings['same_month_start_pattern'] ?: '',
+ '#maxlength' => 100,
+ '#description' => $this->t('A user-defined date format. See the PHP manual for available options.'),
+ '#parents' => ['date_settings', 'same_month_start_pattern'],
+ ];
+
+ $form['date']['same_month']['same_month_end_pattern'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('End date pattern'),
+ '#default_value' => $date_settings['same_month_end_pattern'] ?: '',
+ '#maxlength' => 100,
+ '#description' => $this->t('A user-defined date format. See the PHP manual for available options.'),
+ '#parents' => ['date_settings', 'same_month_end_pattern'],
+ ];
+
+ $form['date']['same_year'] = [
+ '#type' => 'details',
+ '#title' => $this->t('Same year'),
+ '#open' => TRUE,
+ '#weight' => 2,
+ '#group' => 'date',
+ '#description' => $this->t('Optional formatting of date ranges that span multiple months within the same year.'),
+ ];
+
+ $form['date']['same_year']['same_year_start_pattern'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Start date pattern'),
+ '#default_value' => $date_settings['same_year_start_pattern'] ?: '',
+ '#maxlength' => 100,
+ '#description' => $this->t('A user-defined date format. See the PHP manual for available options.'),
+ '#parents' => ['date_settings', 'same_year_start_pattern'],
+ ];
+
+ $form['date']['same_year']['same_year_end_pattern'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('End date pattern'),
+ '#default_value' => $date_settings['same_year_end_pattern'] ?: '',
+ '#maxlength' => 100,
+ '#description' => $this->t('A user-defined date format. See the PHP manual for available options.'),
+ '#parents' => ['date_settings', 'same_year_end_pattern'],
+ ];
+
+ $datetime_settings = $format->getDateTimeSettings();
+
+ $form['datetime'] = [
+ '#type' => 'vertical_tabs',
+ '#title' => $this->t('Date & time formats'),
+ ];
+
+ $form['datetime']['basic'] = [
+ '#type' => 'details',
+ '#title' => $this->t('Basic'),
+ '#open' => TRUE,
+ '#weight' => 1,
+ '#group' => 'datetime',
+ '#description' => $this->t('Basic date and time format used for single date/times, or ranges that cannot be shown in a compact form.'),
+ ];
+
+ $form['datetime']['basic']['default_pattern'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Pattern'),
+ '#default_value' => $datetime_settings['default_pattern'] ?: '',
+ '#maxlength' => 100,
+ '#description' => $this->t('A user-defined date format. See the PHP manual for available options.'),
+ '#required' => TRUE,
+ '#parents' => ['datetime_settings', 'default_pattern'],
+ ];
+
+ $form['datetime']['basic']['separator'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Separator'),
+ '#default_value' => $datetime_settings['separator'] ?: '',
+ '#maxlength' => 100,
+ '#size' => 10,
+ '#description' => $this->t('Text between start and end date/times.'),
+ '#required' => FALSE,
+ '#parents' => ['datetime_settings', 'separator'],
+ ];
+
+ $form['datetime']['same_day'] = [
+ '#type' => 'details',
+ '#title' => $this->t('Same day'),
+ '#open' => TRUE,
+ '#weight' => 2,
+ '#group' => 'datetime',
+ '#description' => $this->t('Optional formatting of time ranges within a single day.'),
+ ];
+
+ $form['datetime']['same_day']['same_day_start_pattern'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Start date/time pattern'),
+ '#default_value' => $datetime_settings['same_day_start_pattern'] ?: '',
+ '#maxlength' => 100,
+ '#description' => $this->t('A user-defined date format. See the PHP manual for available options.'),
+ '#parents' => ['datetime_settings', 'same_day_start_pattern'],
+ ];
+
+ $form['datetime']['same_day']['same_day_end_pattern'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('End date/time pattern'),
+ '#default_value' => $datetime_settings['same_day_end_pattern'] ?: '',
+ '#maxlength' => 100,
+ '#description' => $this->t('A user-defined date format. See the PHP manual for available options.'),
+ '#parents' => ['datetime_settings', 'same_day_end_pattern'],
+ ];
+
+ return $form;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function save(array $form, FormStateInterface $form_state) {
+ $date_range_format = $this->entity;
+ $status = $date_range_format->save();
+
+ switch ($status) {
+ case SAVED_NEW:
+ drupal_set_message($this->t('Created the %label date range format.', [
+ '%label' => $date_range_format->label(),
+ ]));
+ break;
+
+ default:
+ drupal_set_message($this->t('Updated the %label date range format.', [
+ '%label' => $date_range_format->label(),
+ ]));
+ }
+ $form_state->setRedirectUrl($date_range_format->toUrl('collection'));
+ }
+
+}
only in patch2:
unchanged:
--- /dev/null
+++ b/modules/contrib/datetime_extras/modules/datetime_extras_daterange/src/Plugin/Field/FieldFormatter/DateRangeCompactFormatter.php
@@ -0,0 +1,168 @@
+ elements, with
+ * configurable date formats (from the list of configured formats) and a
+ * separator.
+ *
+ * @FieldFormatter(
+ * id = "datetime_extras_daterange",
+ * label = @Translation("Datetime Format"),
+ * field_types = {
+ * "daterange"
+ * }
+ * )
+ */
+class DateRangeCompactFormatter extends FormatterBase implements ContainerFactoryPluginInterface {
+
+ /**
+ * The date range formatter service.
+ *
+ * @var \Drupal\datetime_extras_daterange\DateRangeFormatterInterface
+ */
+ protected $dateRangeFormatter;
+
+ /**
+ * The date range format entity storage.
+ *
+ * @var \Drupal\Core\Entity\EntityStorageInterface
+ */
+ protected $dateRangeFormatStorage;
+
+ /**
+ * Constructs a new DateRangeCompactFormatter.
+ *
+ * @param string $plugin_id
+ * The plugin_id for the formatter.
+ * @param mixed $plugin_definition
+ * The plugin implementation definition.
+ * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
+ * The definition of the field to which the formatter is associated.
+ * @param array $settings
+ * The formatter settings.
+ * @param string $label
+ * The formatter label display setting.
+ * @param string $view_mode
+ * The view mode.
+ * @param array $third_party_settings
+ * Third party settings.
+ * @param \Drupal\datetime_extras_daterange\DateRangeFormatterInterface $date_range_formatter
+ * The date formatter service.
+ * @param \Drupal\Core\Entity\EntityStorageInterface $date_range_format_storage
+ * The date format entity storage.
+ */
+ public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, DateRangeFormatterInterface $date_range_formatter, EntityStorageInterface $date_range_format_storage) {
+ parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
+
+ $this->dateRangeFormatter = $date_range_formatter;
+ $this->dateRangeFormatStorage = $date_range_format_storage;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
+ return new static(
+ $plugin_id,
+ $plugin_definition,
+ $configuration['field_definition'],
+ $configuration['settings'],
+ $configuration['label'],
+ $configuration['view_mode'],
+ $configuration['third_party_settings'],
+ $container->get('datetime_extras_daterange.date_range.formatter'),
+ $container->get('entity_type.manager')->getStorage('daterange_range_format')
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function defaultSettings() {
+ return [
+ 'format_type' => 'medium',
+ ] + parent::defaultSettings();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function settingsForm(array $form, FormStateInterface $form_state) {
+ $form = parent::settingsForm($form, $form_state);
+
+ $format_types = $this->dateRangeFormatStorage->loadMultiple();
+ $options = [];
+ foreach ($format_types as $type => $type_info) {
+ $options[$type] = $type_info->label();
+ }
+
+ $form['format_type'] = [
+ '#type' => 'select',
+ '#title' => $this->t('Date and time range format'),
+ '#description' => $this->t("Choose a format for displaying the date and time range."),
+ '#options' => $options,
+ '#default_value' => $this->getSetting('format_type'),
+ ];
+
+ return $form;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function settingsSummary() {
+ $summary = parent::settingsSummary();
+ $summary[] = $this->t('Format: @format', ['@format' => $this->getSetting('format_type')]);
+ return $summary;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function viewElements(FieldItemListInterface $items, $langcode) {
+ $elements = [];
+
+ foreach ($items as $delta => $item) {
+ if (!empty($item->start_date) && !empty($item->end_date)) {
+ $start_timestamp = $item->start_date->getTimestamp();
+ $end_timestamp = $item->end_date->getTimestamp();
+ $format = $this->getSetting('format_type');
+
+ if ($this->getFieldSetting('datetime_type') == DateTimeItem::DATETIME_TYPE_DATE) {
+ $timezone = DATETIME_STORAGE_TIMEZONE;
+ $text = $this->dateRangeFormatter->formatDateRange($start_timestamp, $end_timestamp, $format, $timezone);
+ }
+ else {
+ $timezone = drupal_get_user_timezone();
+ $text = $this->dateRangeFormatter->formatDateTimeRange($start_timestamp, $end_timestamp, $format, $timezone);
+ }
+
+ $elements[$delta] = [
+ '#plain_text' => $text,
+ '#cache' => [
+ 'contexts' => [
+ 'timezone',
+ ],
+ ],
+ ];
+ }
+ }
+
+ return $elements;
+ }
+
+}