diff --git a/fullcalendar_view.theme.inc b/fullcalendar_view.theme.inc index 2eb07b9..fbb6252 100644 --- a/fullcalendar_view.theme.inc +++ b/fullcalendar_view.theme.inc @@ -275,14 +275,47 @@ function template_preprocess_views_view_fullcalendar(array &$variables) { ]; if (!empty($start_date)) { - // There might be more than one value for a field, - // but we only need the first one and ignore others. - $start_date = reset($start_date)['value']; + // There might be more than one value for a field, so use only one. + $type = $row->_entity->getEntityTypeId(); + $delta_key = $type . '__' . $start_field . '_delta'; + if (property_exists($row, $delta_key)) { + // Use the delta to retrieve the proper value. + $delta = $row->$delta_key; + $start_date = $start_date[$delta]['value']; + } + else { + // Default to the first value. + $start_date = reset($start_date)['value']; + $delta = FALSE; + } // Examine the field type. if ($start_field_option['type'] === 'timestamp') { $start_date = intval($start_date); $start_date = date(DATE_ATOM, $start_date); } + elseif (strpos($start_field_option['type'], 'smartdate') === 0) { + // Process start and end right away, since a Smart Date will always + // include both values. + $start_date = intval($start_date); + if ($delta === FALSE) { + $end_date = reset($end_date)['end_value']; + } + else { + $end_date = $end_date[$delta]['end_value']; + } + $end_date = intval($end_date); + + // Check for how Smart Date stores all day events + // and format appropriately. + if (date('Hi', $start_date) == "0000" && date('Hi', $end_date) == "2359") { + $start_date = date('Y-m-d', $start_date); + $end_date = date('Y-m-d', $end_date); + } + else { + $start_date = date(DATE_ATOM, $start_date); + $end_date = date(DATE_ATOM, $end_date); + } + } elseif (strpos($start_field_option['type'], 'datetime') === FALSE && strpos($start_field_option['type'], 'daterange') === FALSE) { // This field is not a valid date time field. continue; @@ -341,6 +374,9 @@ function template_preprocess_views_view_fullcalendar(array &$variables) { $end_date = intval($end_date); $end_date = date(DATE_ATOM, $end_date); } + elseif (strpos($end_field_option['type'], 'smartdate') === 0) { + // Do nothing here, since we already processed the end value. + } elseif (strpos($end_field_option['type'], 'daterange') !== FALSE) { $end_date = $end_date[0]['end_value']; }