1 date.theme.inc | template_preprocess_date_views_pager(&$variables) |
Preprocess function for Date pager template.
Related topics
File
- core/
modules/ date/ date.theme.inc, line 510 - Theme and preprocess functions for output by Date module.
Code
function template_preprocess_date_views_pager(&$variables) {
backdrop_add_css(backdrop_get_path('module', 'date') . "/css/date-views.css");
$plugin = $variables['plugin'];
$input = $variables['input'];
$view = $plugin->view;
$variables['nav_title'] = '';
$variables['next_url'] = '';
$variables['prev_url'] = '';
$variables['classes'] = array('date-nav-wrapper');
if (empty($view->date_info) || empty($view->date_info->min_date)) {
return;
}
$date_info = $view->date_info;
// Make sure we have some sort of granularity.
$granularity = !empty($date_info->granularity) ? $date_info->granularity : 'month';
$pos = $date_info->date_arg_pos;
if (!empty($input)) {
$id = $plugin->options['date_id'];
if (array_key_exists($id, $input) && !empty($input[$id])) {
$view->args[$pos] = $input[$id];
}
}
$next_args = $view->args;
$prev_args = $view->args;
$min_date = $date_info->min_date;
$max_date = $date_info->max_date;
// Set up the pager link format. Setting the block identifier
// will force pager style links.
if ((isset($date_info->date_pager_format) && $date_info->date_pager_format != 'clean') || !empty($date_info->mini)) {
if (empty($date_info->block_identifier)) {
$date_info->block_identifier = $date_info->pager_id;
}
}
if (empty($date_info->hide_nav)) {
$prev_date = $date_info->prev_date;
$next_date = $date_info->next_date;
$format = array('year' => 'Y', 'month' => 'Y-m', 'day' => 'Y-m-d', 'hour' => 'Y-m-d\TH');
if (!empty($prev_date)) {
switch ($granularity) {
case 'week':
$prev_week = date_week(date_format($prev_date, 'Y-m-d'));
$prev_arg = date_format($prev_date, 'o-\W') . date_pad($prev_week);
break;
default:
$prev_arg = date_format($prev_date, $format[$granularity]);
}
$prev_path = str_replace($date_info->date_arg, $prev_arg, $date_info->url);
$prev_args[$pos] = $prev_arg;
$variables['prev_url'] = date_pager_url($view, NULL, $prev_arg);
}
if (!empty($next_date)) {
switch ($granularity) {
case 'week':
$next_week = date_week(date_format($next_date, 'Y-m-d'));
$next_arg = date_format($next_date, 'o-\W') . date_pad($next_week);
break;
default:
$next_arg = date_format($next_date, $format[$granularity]);
}
$next_path = str_replace($date_info->date_arg, $next_arg, $date_info->url);
$next_args[$pos] = $next_arg;
$variables['next_url'] = date_pager_url($view, NULL, $next_arg);
}
$variables['next_options'] = $variables['prev_options'] = array();
}
else {
$next_path = '';
$prev_path = '';
$variables['next_url'] = '';
$variables['prev_url'] = '';
$variables['next_options'] = $variables['prev_options'] = array();
}
// Check whether navigation links would point to
// a date outside the allowed range.
if (!empty($next_date) && !empty($variables['next_url']) && date_format($next_date, 'Y') > $date_info->limit[1]) {
$variables['next_url'] = '';
}
if (!empty($prev_date) && !empty($variables['prev_url']) && date_format($prev_date, 'Y') < $date_info->limit[0]) {
$variables['prev_url'] = '';
}
$variables['prev_options'] += array('attributes' => array());
$variables['next_options'] += array('attributes' => array());
$prev_title = '';
$next_title = '';
// Build next/prev link titles.
switch ($granularity) {
case 'year':
$prev_title = t('Navigate to previous year');
$next_title = t('Navigate to next year');
break;
case 'month':
$prev_title = t('Navigate to previous month');
$next_title = t('Navigate to next month');
break;
case 'week':
$prev_title = t('Navigate to previous week');
$next_title = t('Navigate to next week');
break;
case 'day':
$prev_title = t('Navigate to previous day');
$next_title = t('Navigate to next day');
break;
}
$variables['prev_options']['attributes'] += array('title' => $prev_title);
$variables['next_options']['attributes'] += array('title' => $next_title);
// Add nofollow for next/prev links.
$variables['prev_options']['attributes'] += array('rel' => 'nofollow');
$variables['next_options']['attributes'] += array('rel' => 'nofollow');
// Need this so we can use '«' or images in the links.
$variables['prev_options'] += array('html' => TRUE);
$variables['next_options'] += array('html' => TRUE);
$link = FALSE;
// Month navigation titles are used as links in the block view.
if (!empty($date_info->mini) && $granularity == 'month') {
$link = TRUE;
}
$params = array(
'granularity' => $granularity,
'view' => $view,
'link' => $link,
);
$nav_title = theme('date_nav_title', $params);
$variables['nav_title'] = $nav_title;
$variables['mini'] = !empty($date_info->mini);
}