You are here

function views_navigation_get_links in Views navigation 7

Build and render the previous/next links for the entity being viewed.

2 calls to views_navigation_get_links()
views_navigation_block_view in ./views_navigation.module
Implements hook_block_view().
views_navigation_node_view in ./views_navigation.module
Implements hook_node_view().

File

./views_navigation.inc, line 212
Views navigation main include file.

Code

function views_navigation_get_links($view_mode = 'full') {

  // Ensure we can show links.
  $cid = isset($_GET[VIEWS_NAVIGATION_CACHE_ID_PARAMETER]) ? $_GET[VIEWS_NAVIGATION_CACHE_ID_PARAMETER] : NULL;
  $pos = isset($_GET[VIEWS_NAVIGATION_POSITION_PARAMETER]) ? $_GET[VIEWS_NAVIGATION_POSITION_PARAMETER] : NULL;
  if (!isset($cid) || !isset($pos) || $view_mode != 'full') {
    return FALSE;
  }
  $query = views_navigation_get_cached_query($cid);
  if (!$query) {
    return FALSE;
  }
  $data = [];
  if ($query->view->display_handler
    ->get_option('views_navigation') && ($query->view->display_handler
    ->get_option('views_navigation_cycle') || $pos > 0)) {
    $data['previous'] = [
      'default_title' => t('Previous'),
      'pos' => $pos - 1,
      'back pos' => NULL,
    ];
  }
  if (isset($query->view->back_destination)) {
    $data['back'] = [
      'default_title' => isset($query->view->back_title) ? t('Back to %title', [
        '%title' => $query->view->back_title,
      ]) : t('Back'),
      'pos' => 'back',
      'back pos' => $pos,
    ];
  }
  if ($query->view->display_handler
    ->get_option('views_navigation') && ($query->view->display_handler
    ->get_option('views_navigation_cycle') || $pos < $query->view->total_rows - 1)) {
    $data['next'] = [
      'default_title' => t('Next'),
      'pos' => $pos + 1,
      'back pos' => NULL,
    ];
  }
  $links = [];
  foreach ($data as $key => $value) {
    if ($query->view->display_handler
      ->get_option('views_navigation_seo_first')) {
      list($path, $options, $text) = _views_navigation_get_data($cid, $value['pos'], $value['back pos'], TRUE);
      $links[$key] = $options;
      $links[$key]['title'] = isset($text) ? $text : $value['default_title'];
      $links[$key]['href'] = $path;
    }
    else {
      $path_parts = [
        'views_navigation',
        $cid,
        $value['pos'],
      ];
      if (!empty($value['back pos'])) {
        $path_parts[] = $value['back pos'];
      }
      $links[$key]['title'] = $value['default_title'];
      $links[$key]['href'] = implode('/', $path_parts);
      $links[$key]['attributes']['rel'] = 'nofollow';
    }
    $links[$key]['html'] = TRUE;
    $links[$key]['attributes']['class'] = [
      'views-navigation-' . $key,
    ];
  }

  // Allow modules to alter the navigation links.
  drupal_alter('views_navigation_navigation_links', $links, $cid, $pos);
  return [
    '#theme' => 'links',
    '#links' => $links,
  ];
}