You are here

protected function DateRecurBasicFormatter::buildDateRangeValue in Recurring Dates Field 3.0.x

Same name and namespace in other branches
  1. 8.2 src/Plugin/Field/FieldFormatter/DateRecurBasicFormatter.php \Drupal\date_recur\Plugin\Field\FieldFormatter\DateRecurBasicFormatter::buildDateRangeValue()
  2. 3.x src/Plugin/Field/FieldFormatter/DateRecurBasicFormatter.php \Drupal\date_recur\Plugin\Field\FieldFormatter\DateRecurBasicFormatter::buildDateRangeValue()
  3. 3.1.x src/Plugin/Field/FieldFormatter/DateRecurBasicFormatter.php \Drupal\date_recur\Plugin\Field\FieldFormatter\DateRecurBasicFormatter::buildDateRangeValue()

Builds a date range suitable for rendering.

Parameters

\Drupal\Core\Datetime\DrupalDateTime $startDate: The start date.

\Drupal\Core\Datetime\DrupalDateTime $endDate: The end date.

bool $isOccurrence: Whether the range is an occurrence of a repeating value.

Return value

array A render array.

2 calls to DateRecurBasicFormatter::buildDateRangeValue()
DateRecurBasicFormatter::settingsSummary in src/Plugin/Field/FieldFormatter/DateRecurBasicFormatter.php
Returns a short summary for the current formatter settings.
DateRecurBasicFormatter::viewItem in src/Plugin/Field/FieldFormatter/DateRecurBasicFormatter.php
Generate the output appropriate for a field item.

File

src/Plugin/Field/FieldFormatter/DateRecurBasicFormatter.php, line 399

Class

DateRecurBasicFormatter
Basic recurring date formatter.

Namespace

Drupal\date_recur\Plugin\Field\FieldFormatter

Code

protected function buildDateRangeValue(DrupalDateTime $startDate, DrupalDateTime $endDate, $isOccurrence) : array {
  $this->formatType = $isOccurrence ? $this
    ->getSetting('occurrence_format_type') : $this
    ->getSetting('format_type');
  $startDateString = $this
    ->buildDateWithIsoAttribute($startDate);

  // Show the range if start and end are different, otherwise only start date.
  if ($startDate
    ->getTimestamp() === $endDate
    ->getTimestamp()) {
    return $startDateString;
  }
  else {

    // Start date and end date are different.
    $this->formatType = $startDate
      ->format('Ymd') == $endDate
      ->format('Ymd') ? $this
      ->getSetting('same_end_date_format_type') : $this
      ->getSetting('occurrence_format_type');
    $endDateString = $this
      ->buildDateWithIsoAttribute($endDate);
    return [
      'start_date' => $startDateString,
      'separator' => [
        '#plain_text' => $this
          ->getSetting('separator'),
      ],
      'end_date' => $endDateString,
    ];
  }
}