public function IcalFieldsWizard::addDateRecurEvent in Views iCal 8
1 call to IcalFieldsWizard::addDateRecurEvent()
- IcalFieldsWizard::render in src/
Plugin/ views/ row/ IcalFieldsWizard.php - Render a row object. This usually passes through to a theme template of some form, but not always.
File
- src/
Plugin/ views/ row/ IcalFieldsWizard.php, line 551 - Contains \Drupal\views_ical\Plugin\views\row\Fields.
Class
- IcalFieldsWizard
- The 'Ical Fields' row plugin
Namespace
Drupal\views_ical\Plugin\views\rowCode
public function addDateRecurEvent(array &$events, ResultRow $row, \DateTimeZone $timezone, array $field_mapping) : void {
/** @var \Drupal\date_recur\Plugin\Field\FieldType\DateRecurItem[] $field_items */
$entity = $this
->getEntity($row);
$field_items = $entity->{$field_mapping['date_field']};
foreach ($field_items as $index => $item) {
/** @var \Drupal\date_recur\DateRange[] $occurrences */
$occurrences = $item
->getHelper()
->getOccurrences();
$future_events = [];
foreach ($occurrences as $occurrence) {
$event = $this
->createDefaultEvent($entity, $field_mapping, $row);
/** @var \DateTime $start_datetime */
$start_datetime = $occurrence
->getStart();
$start_datetime
->setTimezone($timezone);
$event
->setDtStart($start_datetime);
/** @var \DateTime $end_datetime */
$end_datetime = $occurrence
->getEnd();
$end_datetime
->setTimezone($timezone);
$event
->setDtEnd($end_datetime);
$current_date = date_create();
// Only include future occurrences and only the first one because we will rely on rrules.
if ($start_datetime > $current_date) {
$future_events[] = $event;
}
}
}
// We only want the soonest upcoming date in the case of recurring dates.
array_reverse($future_events);
$events[] = array_shift($future_events);
}