You are here

public function ViewsIcalHelper::addDateRecurEvent in Views iCal 8

Adds an event.

This is used when the date_field type is `date_recur`.

Parameters

\Eluceo\iCal\Component\Event[] $events: Set of events where the new event will be added.

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity to be used for creating the event.

\DateTimeZone $timezone: Timezone data to be specified to the event.

array $field_mapping: Views field option and entity field name mapping. Example: [ 'date_field' => 'field_event_date', 'summary_field' => 'field_event_summary', 'description_field' => 'field_event_description', ] End of example.

Overrides ViewsIcalHelperInterface::addDateRecurEvent

See also

\Drupal\views_ical\Plugin\views\style\Ical::defineOptions

File

src/ViewsIcalHelper.php, line 283

Class

ViewsIcalHelper
Helper methods for views_ical.

Namespace

Drupal\views_ical

Code

public function addDateRecurEvent(array &$events, ResultRow $row, \DateTimeZone $timezone, array $field_mapping) : void {

  /** @var \Drupal\date_recur\Plugin\Field\FieldType\DateRecurItem[] $field_items */
  $entity = $row->_entity;
  $field_items = $entity->{$field_mapping['date_field']};
  foreach ($field_items as $index => $item) {

    /** @var \Drupal\date_recur\DateRange[] $occurrences */
    $occurrences = $item
      ->getHelper()
      ->getOccurrences();
    foreach ($occurrences as $occurrence) {
      $event = $this
        ->createDefaultEvent($entity, $field_mapping);

      /** @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);
      $events[] = $event;
    }
  }
}