function _views_navigation_get_data in Views navigation 7
Helper function to get the data.
Return an array containing $path and $options, as needed by url() and drupal_goto() functions. If $get_label is set, the third value will be the entity's label, else NULL.
2 calls to _views_navigation_get_data()
- views_navigation_get_links in ./
views_navigation.inc - Build and render the previous/next links for the entity being viewed.
- views_navigation_router in ./
views_navigation.inc - Redirect to the next or previous entity.
File
- ./
views_navigation.inc, line 412 - Views navigation main include file.
Code
function _views_navigation_get_data($cid, $pos, $back_pos = NULL, $get_label = FALSE) {
if ($query = views_navigation_get_cached_query($cid)) {
if ($pos === 'back') {
if (isset($query->view->back_destination)) {
$options = $query->view->back_destination;
if ($pager = $query->pager_backup) {
if (!empty($back_pos)) {
$options['query']['page'] = floor($back_pos / $pager->options['items_per_page']);
}
}
return [
$options['path'],
$options,
NULL,
];
}
}
elseif ($result = views_navigation_get_result($cid)) {
// Manage array ends, cycling behavior.
$max_index = count($result) - 1;
$pos = $pos > $max_index ? 0 : ($pos < 0 ? $max_index : $pos);
if ($etid = $result[$pos]) {
$params = [
VIEWS_NAVIGATION_POSITION_PARAMETER => $pos,
VIEWS_NAVIGATION_CACHE_ID_PARAMETER => $cid,
];
$entity_type = _views_navigation_get_entity_type($query);
$entities = entity_load($entity_type, [
$etid,
]);
$entity = reset($entities);
$uri = entity_uri($entity_type, $entity);
$uri['options']['query'] = $params;
$return = [
$uri['path'],
$uri['options'],
];
if ($get_label) {
$return[] = entity_label($entity_type, $entity);
}
else {
$return[] = NULL;
}
return $return;
}
}
}
}