Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
fde09054
Commit
fde09054
authored
Apr 25, 2009
by
webchick
Browse files
#444920
by Damien Tournoud: Fix broken book breadcrumbs (with tests).
parent
279f33c6
Changes
2
Hide whitespace changes
Inline
Side-by-side
modules/book/book.module
View file @
fde09054
...
...
@@ -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'
]))
{
...
...
@@ -689,37 +689,6 @@ function book_menu_name($bid) {
return
'book-toc-'
.
$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().
*/
...
...
@@ -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
);
}
}
/**
...
...
modules/book/book.test
View file @
fde09054
...
...
@@ -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.'
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment