You are here

public function IcalFieldsWizard::render in Views iCal 8

Render a row object. This usually passes through to a theme template of some form, but not always.

Parameters

object $row: A single row of the query result, so an element of $view->result.

Return value

string The rendered output of a single row, used by the style plugin.

Overrides RowPluginBase::render

File

src/Plugin/views/row/IcalFieldsWizard.php, line 53
Contains \Drupal\views_ical\Plugin\views\row\Fields.

Class

IcalFieldsWizard
The 'Ical Fields' row plugin

Namespace

Drupal\views_ical\Plugin\views\row

Code

public function render($row) {
  $renderer = $this
    ->getRenderer();
  $style = $this->view
    ->getStyle();
  $style_options = $style->options;

  /** @var \Drupal\Core\Field\FieldDefinitionInterface[] $field_storage_definitions */

  //    $field_storage_definitions = $style->entityFieldManager->getFieldStorageDefinitions($this->view->field[$options['date_field']]->definition['entity_type']);
  $entity_field_manager = $style
    ->getEntityFieldManager();
  if (!isset($style_options['date_field'])) {

    // If this is not set for some reason (dev is just starting out to create
    // a view?), don't try to render. We can't have an event without a date.
    return;
  }
  $field_storage_definitions = $entity_field_manager
    ->getFieldStorageDefinitions($this->view->field[$style_options['date_field']]->definition['entity_type']);

  //$date_field = $this->view->field[$options['date_field']];
  $date_field_definition = $field_storage_definitions[$this->view->field[$style_options['date_field']]->definition['field_name']];

  /** @var string $date_field_type */
  $date_field_type = $date_field_definition
    ->getType();
  $events = [];
  $user_timezone = \date_default_timezone_get();

  // Make sure the events are made as per the configuration in view.

  /** @var string $timezone_override */
  $timezone_override = $this->view->field[$style_options['date_field']]->options['settings']['timezone_override'];
  if ($timezone_override) {
    $timezone = new \DateTimeZone($timezone_override);
  }
  else {
    $timezone = new \DateTimeZone($user_timezone);
  }

  // Use date_recur's API to generate the events.
  // Recurring events will be automatically handled here.
  if ($date_field_type === 'date_recur') {
    $this
      ->addDateRecurEvent($events, $row, $timezone, $style_options);
  }
  else {
    if ($date_field_type === 'datetime') {
      $this
        ->addDateTimeEvent($events, $row, $timezone, $style_options);
    }
    else {
      if ($date_field_type === 'daterange') {

        // TODO: are date ranges separate date field types?
        $this
          ->addDateRangeEvent($events, $row, $timezone, $style_options);
      }
      else {
        if ($date_field_type === 'daterange_all_day') {
          throw new \Exception('daterange_all_day fields not supported.');

          //$this->helper->addEvent($events, $row , $timezone, $this->options);
        }
        else {
          if ($date_field_type === 'smartdate') {
            $this
              ->addSmartDateEvent($events, $row, $timezone, $style_options);
          }
        }
      }
    }
  }
  $calendar = $this->view
    ->getStyle()
    ->getCalendar();
  if (!empty($events)) {
    foreach ($events as $event) {
      if ($event) {
        $calendar
          ->addComponent($event);
      }
    }
  }
  return [
    '#theme' => $this
      ->themeFunctions(),
    '#view' => $this->view,
    '#options' => $this->options,
    '#row' => $row,
    '#field_alias' => isset($this->field_alias) ? $this->field_alias : '',
    '#event' => $events,
  ];
}