You are here

public function DateRecurBasicFormatter::viewElements in Recurring Dates Field 3.x

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

Overrides DateTimeRangeTrait::viewElements

File

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

Class

DateRecurBasicFormatter
Basic recurring date formatter.

Namespace

Drupal\date_recur\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) : array {

  // Whether maximum is per field item or in total.
  $isSharedMaximum = !$this
    ->getSetting('count_per_item');

  // Maximum amount of occurrences to be displayed.
  $occurrenceQuota = (int) $this
    ->getSetting('show_next');
  $elements = [];
  foreach ($items as $delta => $item) {
    $value = $this
      ->viewItem($item, $occurrenceQuota);
    $occurrenceQuota -= $isSharedMaximum ? count($value['#occurrences']) : 0;
    $elements[$delta] = $value;
    if ($occurrenceQuota <= 0) {
      break;
    }
  }
  return $elements;
}