summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/book/book.module56
-rw-r--r--modules/book/book.test51
2 files changed, 52 insertions, 55 deletions
diff --git a/modules/book/book.module b/modules/book/book.module
index be1f7138d..d0132e640 100644
--- a/modules/book/book.module
+++ b/modules/book/book.module
@@ -63,7 +63,7 @@ function book_perm() {
/**
* Inject links into $node as needed.
*/
-function book_node_view_link($node, $teaser, $page) {
+function book_node_view_link($node, $teaser) {
$links = array();
if (isset($node->book['depth'])) {
@@ -690,37 +690,6 @@ function book_menu_name($bid) {
}
/**
- * Build an active trail to show in the breadcrumb.
- */
-function book_build_active_trail($book_link) {
- static $trail;
-
- if (!isset($trail)) {
- $trail = array();
- $trail[] = array('title' => t('Home'), 'href' => '<front>', 'localized_options' => array());
-
- $tree = menu_tree_all_data($book_link['menu_name'], $book_link);
- $curr = array_shift($tree);
-
- while ($curr) {
- if ($curr['link']['href'] == $book_link['href']) {
- $trail[] = $curr['link'];
- $curr = FALSE;
- }
- else {
- if ($curr['below'] && $curr['link']['in_active_trail']) {
- $trail[] = $curr['link'];
- $tree = $curr['below'];
- }
- $curr = array_shift($tree);
- }
- }
- }
-
- return $trail;
-}
-
-/**
* Implementation of hook_node_load().
*/
function book_node_load($nodes, $types) {
@@ -736,22 +705,31 @@ function book_node_load($nodes, $types) {
/**
* Implementation of hook_node_view().
*/
-function book_node_view($node, $teaser, $page) {
+function book_node_view($node, $teaser) {
if (!$teaser) {
if (!empty($node->book['bid']) && $node->build_mode == NODE_BUILD_NORMAL) {
$node->content['book_navigation'] = array(
'#markup' => theme('book_navigation', $node->book),
'#weight' => 100,
);
-
- if ($page) {
- menu_set_active_trail(book_build_active_trail($node->book));
- menu_set_active_menu_name($node->book['menu_name']);
- }
}
}
- book_node_view_link($node, $teaser, $page);
+ book_node_view_link($node, $teaser);
+}
+
+/**
+ * Implementation of hook_page_alter().
+ *
+ * Add the book menu to the list of menus used to build the active trail when
+ * viewing a book page.
+ */
+function book_page_alter(&$page) {
+ if (($node = menu_get_object()) && !empty($node->book['bid'])) {
+ $active_menus = menu_get_active_menu_names();
+ $active_menus[] = $node->book['menu_name'];
+ menu_set_active_menu_names($active_menus);
+ }
}
/**
diff --git a/modules/book/book.test b/modules/book/book.test
index 5f48446bd..872cbc562 100644
--- a/modules/book/book.test
+++ b/modules/book/book.test
@@ -47,16 +47,16 @@ class BookTestCase extends DrupalWebTestCase {
$nodes[] = $this->createBookNode($book->nid); // Node 4.
$this->drupalLogout();
-
- // Check that book pages display.
$this->drupalLogin($web_user);
- $this->checkBookNode($book, array($nodes[0], $nodes[3], $nodes[4]), false, false, $nodes[0]);
- $this->checkBookNode($nodes[0], array($nodes[1], $nodes[2]), $book, $book, $nodes[1]);
- $this->checkBookNode($nodes[1], NULL, $nodes[0], $nodes[0], $nodes[2]);
- $this->checkBookNode($nodes[2], NULL, $nodes[1], $nodes[0], $nodes[3]);
- $this->checkBookNode($nodes[3], NULL, $nodes[2], $book, $nodes[4]);
- $this->checkBookNode($nodes[4], NULL, $nodes[3], $book, false);
+ // Check that book pages display along with the correct outlines and
+ // previous/next links.
+ $this->checkBookNode($book, array($nodes[0], $nodes[3], $nodes[4]), FALSE, FALSE, $nodes[0], array());
+ $this->checkBookNode($nodes[0], array($nodes[1], $nodes[2]), $book, $book, $nodes[1], array($book));
+ $this->checkBookNode($nodes[1], NULL, $nodes[0], $nodes[0], $nodes[2], array($book, $nodes[0]));
+ $this->checkBookNode($nodes[2], NULL, $nodes[1], $nodes[0], $nodes[3], array($book, $nodes[0]));
+ $this->checkBookNode($nodes[3], NULL, $nodes[2], $book, $nodes[4], array($book));
+ $this->checkBookNode($nodes[4], NULL, $nodes[3], $book, FALSE, array($book));
$this->drupalLogout();
@@ -74,25 +74,27 @@ class BookTestCase extends DrupalWebTestCase {
// First we must set $this->book to the second book, so that the
// correct regex will be generated for testing the outline.
$this->book = $other_book;
- $this->checkBookNode($other_book, array($node), false, false, $node);
- $this->checkBookNode($node, NULL, $other_book, $other_book, false);
+ $this->checkBookNode($other_book, array($node), FALSE, FALSE, $node, array());
+ $this->checkBookNode($node, NULL, $other_book, $other_book, FALSE, array($other_book));
}
/**
* Check the outline of sub-pages; previous, up, and next; and printer friendly version.
*
- * @param Node $node
+ * @param $node
* Node to check.
- * @param array $nodes
+ * @param $nodes
* Nodes that should be in outline.
- * @param Node $previous
+ * @param $previous
* Previous link node.
- * @param Node $up
+ * @param $up
* Up link node.
- * @param Node $next
+ * @param $next
* Next link node.
+ * @param $breadcrumb
+ * The nodes that should be displayed in the breadcrumb.
*/
- function checkBookNode($node, $nodes, $previous = false, $up = false, $next = false) {
+ function checkBookNode($node, $nodes, $previous = FALSE, $up = FALSE, $next = FALSE, array $breadcrumb) {
static $number = 0;
$this->drupalGet('node/' . $node->nid);
@@ -117,6 +119,23 @@ class BookTestCase extends DrupalWebTestCase {
$this->assertRaw(l($next->title . ' ›', 'node/' . $next->nid, array('attributes' => array('class' => 'page-next', 'title' => t('Go to next page')))), t('Next page link found.'));
}
+ // Compute the expected breadcrumb.
+ $expected_breadcrumb = array();
+ $expected_breadcrumb[] = url('');
+ foreach ($breadcrumb as $a_node) {
+ $expected_breadcrumb[] = url('node/' . $a_node->nid);
+ }
+
+ // Fetch links in the current breadcrumb.
+ $links = $this->xpath("//div[@class='breadcrumb']/a");
+ $got_breadcrumb = array();
+ foreach ($links as $link) {
+ $got_breadcrumb[] = (string) $link['href'];
+ }
+
+ // Compare expected and got breadcrumbs.
+ $this->assertIdentical($expected_breadcrumb, $got_breadcrumb, t('The breadcrumb is correctly displayed on the page.'));
+
// Check printer friendly version.
$this->drupalGet('book/export/html/' . $node->nid);
$this->assertText($node->title, t('Printer friendly title found.'));