function calendar_preprocess_date_views_pager in Calendar 7.3
Implements hook_preprocess_date_views_pager().
Creates a calendar_links array which is stored in the session and used in calendar_menu_local_tasks_alter() to display the links as action items. The links can be altered or deleted using hook_calendar_links_alter().
File
- ./
calendar.module, line 70 - Adds calendar filtering and displays to Views.
Code
function calendar_preprocess_date_views_pager(&$vars) {
$view = $vars['plugin']->view;
// If no one has added date information, nothing to do here.
if (empty($view->date_info) || empty($view->argument)) {
return;
}
// If we're not on a view with a path (a page), no links are needed.
$current_path = !empty($view->display_handler->options['path']) ? $view->display_handler->options['path'] : '';
if (empty($current_path)) {
return;
}
// If this display has been set up as a default tab, the current path
// is actually the base path, i.e. if the path is 'calendar/month'
// and this is a default tab, the path for this display will actually
// be 'calendar'.
if ($view->display_handler->options['menu']['type'] == 'default tab') {
$parts = explode('/', $current_path);
array_pop($parts);
$current_path = implode('/', $parts);
}
// If an 'Add new ... link is provided, add it here.
if (!empty($view->date_info->calendar_date_link) && !empty($view->date_info->url) && (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);
$calendar_links[$current_path]['actions'][] = array(
'title' => t('Add @name', array(
'@name' => $name,
)),
'path' => $href,
);
}
// Pass this through drupal_alter() so it can be adjusted in custom code or in the theme.
drupal_alter('calendar_links', $calendar_links);
// Add the value to the session so it can be used to create the action links.
if (!empty($calendar_links[$current_path])) {
$_SESSION['calendar_links'][$current_path] = $calendar_links[$current_path];
}
}