Problem/Motivation

Enable book module and add a book. On the subsequent book page, click the "Add child page" link.

The requested node add form has the parent book page parameter in the URL, but the Book select box in Book outline in the vertical tabs does not reflect the parent book page that initiated the new page request.

Screenshot of node/add/book form. The parent page is noted in the URL param but the Book outline vertical tab book select box has - None - selected by default.

Proposed resolution

Update the select box in the Book outline vertical tab to have the indicated book page as the parent.

User interface changes

None.

API changes

None.

Original report by @jessebeach

Comments

jessebeach’s picture

Issue tags: +php-novice, +js-novice
larowlan’s picture

Issue tags: +Needs tests

Def needs tests

larowlan’s picture

Status: Active » Needs review
Issue tags: -js-novice, -Needs tests +Novice
StatusFileSize
new708 bytes

No JavaScript here.
Leaving the fix as part of the Novice task.
But here are the tests - patch should fail.
Hint the issue is with lines 555-> 559 as book_link_load() now returns an EntityInterface, not an array.

Status: Needs review » Needs work

The last submitted patch, 3: book-child-2183779.fail_.patch, failed testing.

lucastockmann’s picture

Assigned: Unassigned » lucastockmann
Status: Needs work » Active
lucastockmann’s picture

I think there is a problem with the book_link_load function. It doesn't adds the bid to the menu_link object. :(
And it's probably a bad idea to load the node object to get the bid from it.

Maybe we should have a closer look on the book_link_load function. Is there anyone who would like to maintain me here?

internetdevels’s picture

Status: Active » Needs review
StatusFileSize
new1.07 KB

This should fix the issue.

internetdevels’s picture

Assigned: lucastockmann » Unassigned

Status: Needs review » Needs work

The last submitted patch, 7: drupal-book_add_child_selection-2183779-7.patch, failed testing.

jessebeach’s picture

+ $route_parameters = unserialize($entity->route_parameters);

I'm guessing that $entity->route_parameters has already been unserialized at this point.

lucastockmann’s picture

Status: Needs work » Needs review
StatusFileSize
new1.2 KB

Improved the patch from comment 7 a bit.

javisr’s picture

StatusFileSize
new88.13 KB

I tested the patch on #11 and i got the expected result

lucastockmann’s picture

StatusFileSize
new1.13 KB

Found a mistake in the patch. There is a unnecessary if-rule ..
I removed it and re-uploaded the patch.

javisr’s picture

StatusFileSize
new29.78 KB

Reviewed. It is working with the expected result.

mcjim’s picture

Issue tags: +Needs tests
StatusFileSize
new1.31 KB

This is a good approach and got further than we did in #2012920: Add child page link in book navigation does not insert parent into book outline.

One important change: $entity->route_parameters['node'] is only loading the $nid, but we need the $bid. We need the actual $bid to make the links work when adding child pages to child pages, etc.

I added a query to bring that in.

There's a test in #2012920: Add child page link in book navigation does not insert parent into book outline that I haven't managed to get working yet.

Status: Needs review » Needs work

The last submitted patch, 15: drupal-adding_a_book_page-2183779-15.patch, failed testing.

The last submitted patch, 15: drupal-adding_a_book_page-2183779-15.patch, failed testing.

mcjim’s picture

Status: Needs work » Postponed

This may not be needed once #2084421: Phase 2 - Decouple book module schema from menu links gets in, as that also fixes this issue.

mcjim’s picture

Status: Postponed » Closed (fixed)