You are here

function template_preprocess_calendar_year in Calendar 8

Same name and namespace in other branches
  1. 6.2 theme/theme.inc \template_preprocess_calendar_year()
  2. 6.2 calendar_multiday/theme/theme.inc \template_preprocess_calendar_year()
  3. 7.3 theme/theme.inc \template_preprocess_calendar_year()
  4. 7 theme/theme.inc \template_preprocess_calendar_year()
  5. 7 calendar_multiday/theme/theme.inc \template_preprocess_calendar_year()
  6. 7.2 theme/theme.inc \template_preprocess_calendar_year()
  7. 7.2 calendar_multiday/theme/theme.inc \template_preprocess_calendar_year()

Display a year view.

File

./calendar.theme.inc, line 92
Theme functions for the Calendar module.

Code

function template_preprocess_calendar_year(&$vars) {

  // Construct a calendar for each month, adjusting the $view passed to the
  // theme so it will produce the right results.
  $view = clone $vars['view'];
  $year = $view->dateInfo
    ->getMinDate()
    ->format('Y');
  $view->styleInfo
    ->setShowWeekNumbers(FALSE);
  $rows = $vars['rows'];
  $months = [];
  foreach ($rows as $month => $month_rows) {

    // Set the month name.
    $month_format = $vars['options']['month_name_size'] == 1 ? "M" : "F";
    $vars['options']['month_name'] = t(date($month_format, mktime(0, 0, 0, $month, 10)));
    $view->dateInfo
      ->setMinMonth($month);
    $view->dateInfo
      ->setGranularity('month');
    $view->styleInfo
      ->setMini(TRUE);
    $view->styleInfo
      ->setShowNavigation(FALSE);
    $view->styleInfo
      ->setShowTitle(TRUE);

    // @todo implement
    // $view->dateInfo->url = date_pager_url($view, NULL, \Drupal\Component\Datetime\DateTimePlus::datePad($year, 4) . '-' . \Drupal\Component\Datetime\DateTimePlus::datePad($month));
    // @todo handle timezone.
    $view->dateInfo
      ->setMinDate(new DateTime($view->dateInfo
      ->getMinYear() . '-' . DateTimePlus::datePad($month) . '-01 00:00:00', new DateTimeZone('europe/brussels')));
    $maxDate = clone $view->dateInfo
      ->getMinDate();
    $maxDate
      ->modify('+1 month');
    $maxDate
      ->modify('-1 second');
    $view->dateInfo
      ->setMaxDate($maxDate);
    $months[$month] = [
      '#theme' => 'calendar_mini',
      '#view' => $view,
      '#options' => $vars['options'],
      '#rows' => $month_rows,
    ];
  }
  $view->styleInfo
    ->setMini(FALSE);
  $vars['months'] = $months;
  $vars['view']->styleInfo
    ->setShowNavigation(TRUE);
  $vars['view']->dateInfo
    ->setGranularity('year');
  $vars['mini'] = FALSE;
}