You are here

public function FullCalendar::getEventStartEndDates in FullCalendar 8.2

Same name and namespace in other branches
  1. 8.5 src/Plugin/views/style/FullCalendar.php \Drupal\fullcalendar\Plugin\views\style\FullCalendar::getEventStartEndDates()
  2. 8.4 src/Plugin/views/style/FullCalendar.php \Drupal\fullcalendar\Plugin\views\style\FullCalendar::getEventStartEndDates()

Get start/end dates for an event.

Parameters

array $fields: Array of date fields for the event.

Return value

array $event_start_end_date The array of dates with 'start' and 'end' keys.

Throws

\Exception

1 call to FullCalendar::getEventStartEndDates()
FullCalendar::prepareEvent in src/Plugin/views/style/FullCalendar.php
Helper method to prepare an event.

File

src/Plugin/views/style/FullCalendar.php, line 553

Class

FullCalendar
Plugin annotation @ViewsStyle( id = "fullcalendar", title = @Translation("FullCalendar"), help = @Translation("Displays items on a calendar."), theme = "views_view--fullcalendar", display_types = {"normal"} )

Namespace

Drupal\fullcalendar\Plugin\views\style

Code

public function getEventStartEndDates(array $fields) {
  $event_start_end_date = [];
  $field = current($fields);

  /** @var \Drupal\Core\Field\FieldStorageDefinitionInterface $field_info */
  $field_info = $field['field_info'];
  switch ($field_info
    ->getType()) {
    case 'datetime':
      $field_names = array_keys($fields);
      if (count($field_names) == 1) {
        $event_start_end_date['start'] = $this
          ->updateEventTimezone($field['value'][0]['raw']->value, $field['timezone_override']);
        $event_start_end_date['end'] = '';
      }
      else {
        $first = $this
          ->updateEventTimezone($fields[$field_names[0]]['value'][0]['raw']->value, $fields[$field_names[0]]['timezone_override']);
        $second = $this
          ->updateEventTimezone($fields[$field_names[1]]['value'][0]['raw']->value, $fields[$field_names[1]]['timezone_override']);
        if ($first > $second) {
          $event_start_end_date['start'] = $second;
          $event_start_end_date['end'] = $first;
        }
        else {
          $event_start_end_date['start'] = $first;
          $event_start_end_date['end'] = $second;
        }
      }
      break;
    case 'daterange':
      $event_start_end_date['start'] = $this
        ->updateEventTimezone($field['value'][0]['raw']->value, $field['timezone_override']);
      $end = $field['value'][0]['raw']->end_value;
      $event_start_end_date['end'] = !empty($end) ? $this
        ->updateEventTimezone($end, $field['timezone_override']) : '';
      break;
    case 'date_recur':

      // @todo:
      break;
  }
  return $event_start_end_date;
}