When using Drupal 7.44, DS 7.x-2.14, and Book made simple 7.x-3.6+17-dev...

I have a custom book type with two additional content types that can serve as book pages. I then created three Display Suite views available for my book and book page content types. The view mode are Full View, and two other view modes. Now the problem...

The Book Navigation field is available for the Full View display mode. I can also position the Book Navigation field wherever I want. All is good with the Full View display mode.

HOWEVER, for my other two display modes, the Book Navigation field is not even listed as a field when configuring the display mode and also does not display on the page.

Any ideas?

I see that this issue or something similar has been discussed at

https://www.drupal.org/node/1082968,
https://www.drupal.org/node/1994186,
and https://www.drupal.org/node/1082968.

Thanks for any help and how can I help to debug this?

Jeff

Comments

webservant316 created an issue. See original summary.

webservant316’s picture

okay I created a custom Display Suite php field until this problem is fixed the right way...

<?php
book_node_view($entity, 'full');
if (!empty($entity->content['book_navigation']['#markup'])) {
	return $entity->content['book_navigation']['#markup'];
}
?>

I then add this field to my additional book page display mode types (except for Full View Mode which was working as expected)

webservant316’s picture

Issue summary: View changes
webservant316’s picture

Not sure I understand all of this, but it could be a basic problem with core. See the core book function below which will only put Book Navigation on $view_mode == 'full'. This may not consider that Display Suite allows for creating Display Mode that are full page, but with names other than 'full'. So again my proposed solution above nicely handles this problem by calling book_node_view_link($node, 'full') for any Display Suite Display Mode.

/**
 * Adds relevant book links to the node's links.
 *
 * @param $node
 *   The book page node to add links to.
 * @param $view_mode
 *   The view mode of the node.
 */
function book_node_view_link($node, $view_mode) {
  $links = array();

  if (isset($node->book['depth'])) {
    if ($view_mode == 'full' && node_is_page($node)) {
      $child_type = variable_get('book_child_type', 'book');
      if ((user_access('add content to books') || user_access('administer book outlines')) && node_access('create', $child_type) && $node->status == 1 && $node->book['depth'] < MENU_MAX_DEPTH) {
        $links['book_add_child'] = array(
          'title' => t('Add child page'),
          'href' => 'node/add/' . str_replace('_', '-', $child_type),
          'query' => array('parent' => $node->book['mlid']),
        );
      }

      if (user_access('access printer-friendly version')) {
        $links['book_printer'] = array(
          'title' => t('Printer-friendly version'),
          'href' => 'book/export/html/' . $node->nid,
          'attributes' => array('title' => t('Show a printer-friendly version of this book page and its sub-pages.'))
        );
      }
    }
  }

  if (!empty($links)) {
    $node->content['links']['book'] = array(
      '#theme' => 'links__node__book',
      '#links' => $links,
      '#attributes' => array('class' => array('links', 'inline')),
    );
  }
}
Bagz’s picture

If anyone arrives here looking for a D8 solution, there is a relatively simple way to create a custom block with the traversal links so it can be placed anywhere in a panelized book page.

class BookTraversalBlock extends BlockBase {

  /**
   * Builds and returns the renderable array for this block plugin.
   */
  public function build() {

    $build = [];
    $node = \Drupal::routeMatch()->getParameter('node');
    if ($node->bundle() == 'book') {
      $build['book_navigation'] = [
        '#theme' => 'book_navigation',
        '#book_link' => $node->book,
        '#weight' => 100,
        // The book navigation is a listing of Node entities, so associate its
        // list cache tag for correct invalidation.
        '#cache' => [
          'tags' => $node->getEntityType()->getListCacheTags(),
        ],
      ];
    }
    return $build;
  }

}

Basically a straight copy of the Book module's code.

mepperly’s picture

I had this issue solved in D7 by making all my book pages "full"--but one of the latest patches (don't know which because I don't have that many books) blew away my book nav that I added in left sidebar with Display Suite.

The block is still there in "Manage Display", but it is not rendering on the page.

One of my developers is deployed and the other is moving house.

I'm a site builder with template access and git-ability, so I can probably implement a fix, but I'm not good enough code-wise to figure out what's going wrong as everything from the UI side looks right.

Help!

webservant316’s picture

Ha, ran into this problem again and found my own solution at #2 above. Still works.

Things like this get me thinking I should write my own CMS to replace Drupal.... if I could live ten more lives.

valsgalore’s picture

The solution in #2 was just what I needed!

However, Book Pages normally come with an "Add child page" link, which I wanted to add in as well. I borrowed from #2 and the core module code shared above to come up with a solution. It could probably be cleaned up a bit, but it is working for me!

So if anyone's interested, here's some code you can use to create a Display Suite field that shows both the book navigation and an "Add child page" link:

<?php
book_node_view($entity, 'full');
$addlink = '';
$child_type = variable_get('book_child_type', 'book');
if ((user_access('add content to books') || user_access('administer book outlines')) && node_access('create', $child_type) && $entity->status == 1 && $entity->book['depth'] < MENU_MAX_DEPTH) {
$links = array(
          'title' => t('Add child page'),
          'href' => 'node/add/' . str_replace('_', '-', $child_type),
          'query' => array('parent' => $entity->book['mlid']),
   );
   $addlink = '<a href="/'.$links['href'].'?parent='.$links['query']['parent'].'">'.$links['title'].'</a>';
}
if (!empty($entity->content['book_navigation']['#markup'])) {
	return $entity->content['book_navigation']['#markup'].$addlink;
}
?>