You are here

protected function DateRecurDefaultFormatter::viewValue in Recurring Dates Field 8

Generate the output appropriate for one field item.

Parameters

DateRecurItem $item: One field item.

Return value

string The textual output generated.

1 call to DateRecurDefaultFormatter::viewValue()
DateRecurDefaultFormatter::viewElements in src/Plugin/Field/FieldFormatter/DateRecurDefaultFormatter.php

File

src/Plugin/Field/FieldFormatter/DateRecurDefaultFormatter.php, line 161

Class

DateRecurDefaultFormatter
Plugin implementation of the 'date_recur_default_formatter' formatter.

Namespace

Drupal\date_recur\Plugin\Field\FieldFormatter

Code

protected function viewValue(DateRecurItem $item) {
  $build = [
    '#theme' => 'date_recur_default_formatter',
  ];
  if (empty($item->end_date)) {
    $item->end_date = clone $item->start_date;
  }
  $build['#date'] = $this
    ->buildDateRangeValue($item->start_date, $item->end_date);
  if (empty($item->rrule)) {
    $build['#isRecurring'] = FALSE;
  }
  else {
    $build['#isRecurring'] = TRUE;
  }
  if ($this
    ->getSetting('show_rrule') && !empty($item->rrule)) {
    $build['#repeatrule'] = $item
      ->getOccurrenceHandler()
      ->humanReadable();
  }
  $build['#occurrences'] = $this
    ->viewOccurrences($item);
  if (!empty($item->_attributes)) {
    $build += $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 $build;
}