You are here

function template_preprocess_calendar_main in Calendar 7.2

Same name in this branch
  1. 7.2 theme/theme.inc \template_preprocess_calendar_main()
  2. 7.2 calendar_multiday/theme/theme.inc \template_preprocess_calendar_main()
Same name and namespace in other branches
  1. 6.2 theme/theme.inc \template_preprocess_calendar_main()
  2. 6.2 calendar_multiday/theme/theme.inc \template_preprocess_calendar_main()
  3. 7 theme/theme.inc \template_preprocess_calendar_main()
  4. 7 calendar_multiday/theme/theme.inc \template_preprocess_calendar_main()

Display a calendar navigation and links

File

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

Code

function template_preprocess_calendar_main(&$vars) {
  if (module_exists('calendar_multiday')) {
    return;
  }
  module_load_include('inc', 'calendar', 'includes/calendar');

  // Add some basic values to the view.
  calendar_basics($vars);
  $view = $vars['view'];
  $displays = $view->date_info->display_types;
  $calendar_links = array();
  $base = array(
    'attributes' => array(
      'rel' => 'nofollow',
    ),
  );
  if (!empty($displays['year'])) {
    $calendar_links['calendar calendar-year'] = $base + array(
      'title' => t('Year', array(), array(
        'context' => 'datetime',
      )),
      'href' => date_real_url($view, 'year'),
    );
  }
  if (!empty($displays['month'])) {
    $calendar_links['calendar calendar-month'] = $base + array(
      'title' => t('Month', array(), array(
        'context' => 'datetime',
      )),
      'href' => date_real_url($view, 'month'),
    );
  }
  if (!empty($displays['week'])) {
    $calendar_links['calendar calendar-week'] = $base + array(
      'title' => t('Week', array(), array(
        'context' => 'datetime',
      )),
      'href' => date_real_url($view, 'week'),
    );
  }
  if (!empty($displays['day'])) {
    $calendar_links['calendar calendar-day'] = $base + array(
      'title' => t('Day', array(), array(
        'context' => 'datetime',
      )),
      'href' => date_real_url($view, 'day'),
    );
  }
  $vars['calendar_links'] = $calendar_links;

  // If the Date Popup module is enabled, add a popup date selector.
  if (!empty($view->date_info->calendar_popup)) {
    $vars['calendar_popup'] = '<div class="clear-block">' . calendar_date_select($view) . '</div>';
  }

  // If an 'Add new ... link is provided, add it here.
  // the query will bring the user back here after adding the node.
  if (!empty($view->date_info->calendar_date_link) && (user_access("administer nodes") || user_access('create ' . $view->date_info->calendar_date_link . ' content'))) {
    $name = node_type_get_name($view->date_info->calendar_date_link);
    $href = 'node/add/' . str_replace('_', '-', $view->date_info->calendar_date_link);
    $query = drupal_get_query_parameters(array(
      'destination' => $view->date_info->url,
    ));
    $vars['calendar_links']['calendar calendar-add'] = $base + array(
      'title' => t('Add+'),
      'href' => $href,
      'query' => $query,
    );
  }
}