Situation
Book structure:
- 1 page
- 2 page
- 3 page
- 3.1 page
- 3.2 page
- 3.3 page
- 4 page
- 5 page
Sub pages expected display
* 1 page
* 2 page
* 3 page
* 4 page
* 5 page
See: book-nav-correct-display.png
Sub pages real display
* 1 page
* 2 page
* 3 page
See: book-nav-incorrect-display.png
The Problem
The following loop is used to build the list of children and the $flat variable is a list of all descendants and if it gets any link that does not meet the condition the while loop is stopped.
In the above example the while is true for page 1,2 and 3 but not true for 3.1 so the loop stops and 4 & 5 are never checked and added as children.
So if any direct children have any children of its own the loop will be stopped and remaining children ignored.
while (($link = array_shift($flat)) && $link['plid'] == $book_link['mlid']) {
$data['link'] = $link;
$data['below'] = '';
$children[] = $data;
}
The solution
The condition should be moved out of the while loop checking into the body of the loop.
while ($link = array_shift($flat)) {
if ($link['plid'] == $book_link['mlid']) {
$data['link'] = $link;
$data['below'] = '';
$children[] = $data;
}
}
This problem exits for:
- Drupal 6.x & 7.x book/book.module - book_children()
- Drupal 8.x book/src/BookOutline.php - childrenLinks()
Comment | File | Size | Author |
---|---|---|---|
#15 | Screen Shot 2020-10-23 at 9.48.52 AM.png | 188.63 KB | mindbet |
#15 | Screen Shot 2020-10-23 at 9.48.04 AM.png | 103.33 KB | mindbet |
#1 | drupal_core-book-2412885.01.d7.patch | 743 bytes | NaX |
book-nav-incorrect-display.png | 6.22 KB | NaX | |
#3 | book-nav-correct-display.png | 11.77 KB | NaX |
Comments
Comment #1
NaX CreditAttribution: NaX commentedHere are patches for D7 and D8.
Comment #3
NaX CreditAttribution: NaX commentedComment #5
larowlanComment #6
mgiffordComment #15
mindbet CreditAttribution: mindbet as a volunteer commentedFor the record, I am unable to reproduce this in Drupal 9.2
Book setup:
Node display showing list of children
Comment #19
quietone CreditAttribution: quietone at PreviousNext commented@mindbet, thanks for the detailed manual testing!
I too manually tested, this time on Drupal 9.4.5 and was not able to reproduce the problem.
Therefore, closing as outdated. If this is incorrect reopen the issue, by setting the status to 'Active', and add a comment explaining what still needs to be done.
Thanks!