You are here

function date_pager_url in Date 8

Same name and namespace in other branches
  1. 7.3 date_views/date_views.module \date_pager_url()
  2. 7.2 date_views/date_views.module \date_pager_url()

A version of date_real_url that formats links correctly for the new Date pager.

2 calls to date_pager_url()
template_preprocess_date_views_pager in date_views/theme/theme.inc
Preprocess function for Date pager template.
theme_date_nav_title in date_views/theme/theme.inc
Theme the calendar title

File

date_views/date_views.module, line 163

Code

function date_pager_url($view, $date_type = NULL, $date_arg = NULL, $force_view_url = FALSE, $absolute = TRUE) {

  // If someone adds a pager without a matching argument, there is not date information to work with.
  if (empty($view->date_info) || !isset($view->date_info->date_arg_pos)) {
    return '';
  }
  $args = $view->args;
  $pos = $view->date_info->date_arg_pos;

  // The View arguments array is indexed numerically but is not necessarily
  // in numerical order. Sort the arguments to ensure the correct order.
  ksort($args);

  // If there are empty arguments before the date argument,
  // pad them with the wildcard so the date argument will be in
  // the right position.
  if (count($args) < $pos) {
    foreach ($view->argument as $name => $argument) {
      if ($argument->position == $pos) {
        break;
      }
      $args[] = $argument->options['exception']['value'];
    }
  }
  if (!empty($date_type)) {
    switch ($date_type) {
      case 'year':
        $args[$pos] = DrupalDateTime::datePad($view->date_info->year, 4);
        break;
      case 'week':
        $args[$pos] = DrupalDateTime::datePad($view->date_info->year, 4) . '-W' . DrupalDateTime::datePad($view->date_info->week);
        break;
      case 'day':
        $args[$pos] = DrupalDateTime::datePad($view->date_info->year, 4) . '-' . DrupalDateTime::datePad($view->date_info->month) . '-' . DrupalDateTime::datePad($view->date_info->day);
        break;
      default:
        $args[$pos] = DrupalDateTime::datePad($view->date_info->year, 4) . '-' . DrupalDateTime::datePad($view->date_info->month);
        break;
    }
  }
  elseif (!empty($date_arg)) {
    $args[$pos] = $date_arg;
  }
  else {
    $args = $view->args;
  }

  // Is this an embedded or a block view?
  // Return the pager query value.
  if (!$force_view_url && (!empty($view->preview) || !empty($view->date_info->block_identifier))) {
    $url = $args[$pos];
    $key = date_block_identifier($view);
    if (!empty($key)) {
      return url($_GET['q'], array(
        'query' => date_views_querystring($view, array(
          $key => $url,
        )),
        'absolute' => $absolute,
      ));
    }
  }

  // Normal views may need querystrings appended to them
  // if they use exposed filters.
  return url($view
    ->get_url($args), array(
    'query' => date_views_querystring($view),
    'absolute' => $absolute,
  ));
}