View source
<?php
define('VIEWS_NAVIGATION_CACHE_BIN', 'cache_views_navigation');
define('VIEWS_NAVIGATION_POSITION_PARAMETER', 'position');
define('VIEWS_NAVIGATION_CACHE_ID_PARAMETER', 'list');
function views_navigation_views_api() {
return [
'api' => 3,
'path' => drupal_get_path('module', 'views_navigation') . '/views',
];
}
function views_navigation_views_plugins() {
$plugins = [];
$plugins['display_extender']['views_navigation'] = [
'title' => t('Views navigation'),
'help' => t('Enable views navigation.'),
'path' => drupal_get_path('module', 'views_navigation') . '/views',
'handler' => 'views_navigation_plugin_display_extender_views_navigation',
];
return $plugins;
}
function views_navigation_views_pre_render(&$view) {
module_load_include('inc', 'views_navigation');
if ($view->display_handler
->get_option('views_navigation') || $view->display_handler
->get_option('views_navigation_back')) {
if ($cid = views_navigation_store_query($view)) {
$view->views_navigation_cid = $cid;
}
}
}
function views_navigation_views_data_alter(&$data) {
foreach ($data as &$table) {
foreach ($table as &$item) {
if (isset($item['field']) && isset($item['field']['handler'])) {
switch ($item['field']['handler']) {
case 'views_handler_field_node':
$item['field']['handler'] = 'views_navigation_handler_field_node';
break;
case 'views_handler_field_node_path':
$item['field']['handler'] = 'views_navigation_handler_field_node_path';
break;
case 'views_handler_field_node_link':
$item['field']['handler'] = 'views_navigation_handler_field_node_link';
break;
case 'views_handler_field_field':
$item['field']['handler'] = 'views_navigation_handler_field_field';
break;
case 'entity_views_handler_field_text':
$item['field']['handler'] = 'views_navigation_handler_entity_field_text';
break;
case 'entity_views_handler_field_field':
$item['field']['handler'] = 'views_navigation_handler_entity_field_field';
break;
case 'entity_views_handler_field_uri':
$item['field']['handler'] = 'views_navigation_handler_entity_field_uri';
break;
case 'entity_views_handler_field_entity':
$item['field']['handler'] = 'views_navigation_handler_entity_field_entity';
break;
}
}
}
}
}
function views_navigation_views_plugins_alter(&$plugins) {
if (isset($plugins['row']['entity'])) {
module_load_include('inc', 'views_navigation', 'views/views_navigation_plugin_entity_row_entity_view');
$plugins['row']['entity']['override handler'] = 'views_navigation_plugin_entity_row_entity_view';
}
if (isset($plugins['row']['ds'])) {
$plugins['row']['ds']['override handler'] = 'views_navigation_plugin_ds_entity_view';
}
}
function views_navigation_node_view($node, $view_mode, $langcode) {
$page_node = menu_get_object('node');
if (!isset($page_node) || $page_node->nid != $node->nid) {
return;
}
module_load_include('inc', 'views_navigation');
$links = views_navigation_get_links($view_mode);
if ($links) {
$node->content['links']['views_navigation'] = $links;
}
}
function views_navigation_menu() {
$items['views_navigation/%/%'] = [
'title' => 'Views navigation router',
'page callback' => 'views_navigation_router',
'page arguments' => [
1,
2,
],
'access callback' => TRUE,
'file' => 'views_navigation.inc',
'type' => MENU_CALLBACK,
];
return $items;
}
function views_navigation_block_info() {
return [
'views_navigation_links' => [
'info' => t('Views navigation prev/next links'),
'cache' => DRUPAL_CACHE_PER_PAGE,
],
];
}
function views_navigation_block_view() {
module_load_include('inc', 'views_navigation');
if ($links = views_navigation_get_links()) {
return [
'subject' => '',
'content' => $links,
];
}
}
function views_navigation_flush_caches() {
return [
VIEWS_NAVIGATION_CACHE_BIN,
];
}