You are here

views_ical.module in Views iCal 8

Same filename and directory in other branches
  1. 7 views_ical.module

File

views_ical.module
View source
<?php

use Eluceo\iCal\Component\Calendar;
use Eluceo\iCal\Component\Timezone;

/**
 * Prepares variables for Views iCal template.
 *
 * Default template: views-view-ical.html.twig.
 *
 * @param array $variables
 *   An associative array containing:
 *   - view: A View object.
 */
function views_ical_preprocess_views_view_ical(&$variables) {
  module_load_include('inc', 'views', 'views.theme');
  $view = $variables['view'];
  $view
    ->getResponse()->headers
    ->set('Content-Type', 'text/calendar; charset=utf-8');
  if ($view->display_handler
    ->getOption('sitename_title')) {
    $config = \Drupal::config('system.site');
    $title = $config
      ->get('name');
    if ($slogan = $config
      ->get('slogan')) {
      $title .= ' - ' . $slogan;
    }
  }
  else {
    $title = $view
      ->getTitle();
  }
  $variables['title'] = $title;
  template_preprocess_views_view_unformatted($variables);
}

/**
 * Prepares variables for Views iCal template.
 *
 * Default template: views-view-ical.html.twig.
 *
 * @param array $variables
 *   An associative array containing:
 *   - view: A View object.
 */
function views_ical_preprocess_views_view_icalwizard(&$variables) {
  return;
  $view = $variables['view'];
  $view
    ->getResponse()->headers
    ->set('Content-Type', 'text/calendar; charset=utf-8');
  if ($view->display_handler
    ->getOption('sitename_title')) {
    $config = \Drupal::config('system.site');
    $title = $config
      ->get('name');
    if ($slogan = $config
      ->get('slogan')) {
      $title .= ' - ' . $slogan;
    }
  }
  else {
    $title = $view
      ->getTitle();
  }
  $variables['title'] = $title;

  // TODO: Need to load library
  $calendar = new Calendar('-//Drupal iCal API//EN');
  $user_timezone = \drupal_get_user_timezone();

  /** @var string $user_timezone */
  $v_timezone = new Timezone($user_timezone);
  $calendar
    ->setTimezone($v_timezone);
  foreach ($variables['rows'] as $row) {
    $calendar
      ->addComponent($row);
  }
  $variables['ical'] = $calendar
    ->render();
  if (false) {
    module_load_include('inc', 'views', 'views.theme');
    $view = $variables['view'];

    //$view->getResponse()->headers->set('Content-Type', 'text/calendar; charset=utf-8');
    if ($view->display_handler
      ->getOption('sitename_title')) {
      $title = $config
        ->get('name');
      if ($slogan = $config
        ->get('slogan')) {
        $title .= ' - ' . $slogan;
      }
    }
    else {
      $title = $view
        ->getTitle();
    }
    $variables['title'] = $title;
  }
  template_preprocess_views_view_fields($variables);
}

/**
 * Prepares variables for Views iCal Fields template.
 *
 * Default template: views-view-ical-fields.html.twig.
 *
 * @param array $variables
 *   An associative array containing:
 *   - view: A View object.
 */
function views_ical_preprocess_views_view_ical_fields(&$variables) {
  module_load_include('inc', 'views', 'views.theme');
  template_preprocess_views_view_fields($variables);
}

Functions

Namesort descending Description
views_ical_preprocess_views_view_ical Prepares variables for Views iCal template.
views_ical_preprocess_views_view_icalwizard Prepares variables for Views iCal template.
views_ical_preprocess_views_view_ical_fields Prepares variables for Views iCal Fields template.