You are here

function template_preprocess_i18n_book_navigation in Book translation 6

Same name and namespace in other branches
  1. 6.2 i18n_book_navigation.module \template_preprocess_i18n_book_navigation()

Similar to template_preprocess_book_navigation() Preprocesses the variables and creates the book navigation for the translated nodes.

File

./i18n_book_navigation.module, line 263

Code

function template_preprocess_i18n_book_navigation(&$variables) {
  $book_link = $variables['book_link'];

  // Make the same query as in menu_tree_all_data()
  // menu_tree_all_data() being dependent on the current
  // path, it is not possible to call it directly, because
  // we need the tree for the real book page node, in the default language
  $tree = menu_tree_data(db_query("\n        SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.*\n        FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path\n        WHERE ml.menu_name = '%s'\n        ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC", $book_link['menu_name']));

  // Get all direct children to create the child tree
  $children = array();
  $children = _i18n_book_navigation_book_children($tree, $book_link['mlid'], TRUE);

  // Create a flat menu tree
  $flat = array();
  _book_flatten_menu(_i18n_book_navigation_sort_by_weigth($tree, TRUE), $flat);
  if ($book_link['mlid']) {
    if ($children) {
      $variables['tree'] = menu_tree_output($children);
    }
    if ($book_link['plid'] && ($prev = _i18n_book_navigation_prev($flat, $book_link))) {
      $prev_href = url($prev['href']);
      drupal_add_link(array(
        'rel' => 'prev',
        'href' => $prev_href,
      ));
      $variables['prev_url'] = $prev_href;
      $variables['prev_title'] = check_plain($prev['title']);
    }
    if ($book_link['plid'] && ($parent = _i18n_book_navigation_up($flat, $book_link))) {
      $parent_href = url($parent['href']);
      drupal_add_link(array(
        'rel' => 'up',
        'href' => $parent_href,
      ));
      $variables['parent_url'] = $parent_href;
      $variables['parent_title'] = check_plain($parent['title']);
    }
    if ($next = _i18n_book_navigation_next($flat, $book_link)) {
      $next_href = url($next['href']);
      drupal_add_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] = '';
    }
  }
}