public function IcalFieldsWizard::addDateTimeEvent in Views iCal 8
Create an event based on a datetime field
Parameters
array $events:
\Drupal\Core\Entity\ContentEntityInterface $entity:
\DateTimeZone $timezone:
array $field_mapping:
1 call to IcalFieldsWizard::addDateTimeEvent()
- 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 405 - Contains \Drupal\views_ical\Plugin\views\row\Fields.
Class
- IcalFieldsWizard
- The 'Ical Fields' row plugin
Namespace
Drupal\views_ical\Plugin\views\rowCode
public function addDateTimeEvent(array &$events, ResultRow $row, \DateTimeZone $timezone, array $field_mapping) : void {
$entity = $this
->getEntity($row);
$utc_timezone = new \DateTimeZone('UTC');
$datefield_values = $entity
->get($field_mapping['date_field'])
->getValue();
// If an end date field was defined, then the content model is most likely
// using two, single cardinality fields for a start and an end date.
if (isset($field_mapping['end_date_field']) && $field_mapping['end_date_field'] != 'none') {
// generate the event
$event = $this
->createDefaultEvent($entity, $field_mapping, $row);
// set the start time.
$date_entry = $datefield_values[0];
$start_datetime = new \DateTime($date_entry['value'], $utc_timezone);
$start_datetime
->setTimezone($timezone);
$event
->setDtStart($start_datetime);
// Set the end time
$end_date_field_values = $entity
->get($field_mapping['end_date_field'])
->getValue();
$end_date_entry = $end_date_field_values[0];
$end_datetime = new \DateTime($end_date_entry['value'], $utc_timezone);
$end_datetime
->setTimezone($timezone);
$event
->setDtEnd($end_datetime);
// All day events.
if (isset($field_mapping['no_time_field']) && $field_mapping['no_time_field'] != 'none') {
$all_day = $entity
->get($field_mapping['no_time_field'])
->getValue();
if ($all_day && isset($all_day[0]['value']) && $all_day[0]['value']) {
$event
->setNoTime(TRUE);
}
}
$events[] = $event;
}
}