function template_preprocess_book_navigation

Same name in other branches
  1. 9 core/modules/book/book.module \template_preprocess_book_navigation()
  2. 8.9.x core/modules/book/book.module \template_preprocess_book_navigation()
  3. 10 core/modules/book/book.module \template_preprocess_book_navigation()
  4. 11.x core/modules/book/book.module \template_preprocess_book_navigation()

Processes variables for book-navigation.tpl.php.

Parameters

$variables: An associative array containing the following key:

  • book_link

See also

book-navigation.tpl.php

File

modules/book/book.module, line 1095

Code

function template_preprocess_book_navigation(&$variables) {
    $book_link = $variables['book_link'];
    // Provide extra variables for themers. Not needed by default.
    $variables['book_id'] = $book_link['bid'];
    $variables['book_title'] = check_plain($book_link['link_title']);
    $variables['book_url'] = 'node/' . $book_link['bid'];
    $variables['current_depth'] = $book_link['depth'];
    $variables['tree'] = '';
    if ($book_link['mlid']) {
        $variables['tree'] = book_children($book_link);
        if ($prev = book_prev($book_link)) {
            $prev_href = url($prev['href']);
            drupal_add_html_head_link(array(
                'rel' => 'prev',
                'href' => $prev_href,
            ));
            $variables['prev_url'] = $prev_href;
            $variables['prev_title'] = check_plain($prev['title']);
        }
        if ($book_link['plid'] && ($parent = book_link_load($book_link['plid']))) {
            $parent_href = url($parent['href']);
            drupal_add_html_head_link(array(
                'rel' => 'up',
                'href' => $parent_href,
            ));
            $variables['parent_url'] = $parent_href;
            $variables['parent_title'] = check_plain($parent['title']);
        }
        if ($next = book_next($book_link)) {
            $next_href = url($next['href']);
            drupal_add_html_head_link(array(
                'rel' => 'next',
                'href' => $next_href,
            ));
            $variables['next_url'] = $next_href;
            $variables['next_title'] = check_plain($next['title']);
        }
    }
    $variables['has_links'] = FALSE;
    // Link variables to filter for values and set state of the flag variable.
    $links = array(
        'prev_url',
        'prev_title',
        'parent_url',
        'parent_title',
        'next_url',
        'next_title',
    );
    foreach ($links as $link) {
        if (isset($variables[$link])) {
            // Flag when there is a value.
            $variables['has_links'] = TRUE;
        }
        else {
            // Set empty to prevent notices.
            $variables[$link] = '';
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.