Problem/Motivation

The re-use of the {menu_links} table by book module has always been a bit of an awkward implementation. I (pwolanin) wanted to build book on tops of the menu link hierarchy handling and by the end of the 6.x cycle, there wasn't time left to do it better than this.

However, looking at the code in book module, a lot will need to be re-factored in terms of queries to decouple from the old router system, so we might want to clean it up.

Also, there is no good reason to have book links be actual menu link entities. In fact, the coupling now between the book module and menu link code is blocking needed finalization of menu link entity since like removing ArrayAccess

Proposed resolution

Combine all the book link fields into one table - essentially copying the hierarchy-related elements from {menu_links}

Simplify the access checking code since we know that all the links will be to nodes.

API changes

The schema will change, and we will move all the APi functions to the book manager behind an interface so that further refactoring can be accomplished, or the implementation changed.

#2100575: [META] - Split book module from menu link

CommentFileSizeAuthor
#133 book_manager-2084421-133.patch101.41 KBdawehner
#131 interdiff-2084421-127-131.txt745 bytesYesCT
#131 book-2084421-131.patch101.42 KBYesCT
#129 interdiff-2084421-127-129.txt452 bytesYesCT
#129 book-2084421-129.patch101.42 KBYesCT
#127 interdiff-2084421-125-127.txt18.13 KBYesCT
#127 book-2084421-127.patch101.43 KBYesCT
#125 book-2084421-125.patch100.42 KBpwolanin
#125 increment.txt616 bytespwolanin
#122 book-2084421-122-with-fixes.patch100.37 KBpwolanin
#122 increment.txt11.33 KBpwolanin
#122 book-2084421-122-only-tests.patch97.03 KBpwolanin
#119 book-2084421-119-with-fixes.patch100.38 KBpwolanin
#119 increment.txt11.33 KBpwolanin
#119 book-2084421-119-only-tests.patch97.04 KBpwolanin
#116 Screen shot 2014-02-26 at 4.27.43 PM.png33.16 KBpwolanin
#111 book-2084421-109.patch95.73 KBpwolanin
#111 increment.txt452 bytespwolanin
#104 book-2084421-104-interdiff.txt943 bytesBerdir
#104 book-2084421-104.patch95.67 KBBerdir
#100 book-2084421-100.patch95.83 KBpwolanin
#100 increment.txt7.49 KBpwolanin
#100 book-2084421-reroll-99.patch94.96 KBpwolanin
#94 drupal_2084421_94.patch94.47 KBXano
#88 book-2084421-87.patch95.89 KBSutharsan
#81 book-2084421-81.patch95.88 KBdawehner
#81 interdiff.txt21.14 KBdawehner
#72 book-2084421-72-failing-test.txt1.63 KBclemens.tolboom
#72 interdiff-71-72.txt5.22 KBclemens.tolboom
#72 book-2084421-72.patch73.36 KBclemens.tolboom
#69 2084421-book-69.patch71.17 KBdawehner
#69 interdiff.txt700 bytesdawehner
#66 book-2084421-66.patch71.18 KBdawehner
#63 book-2084421-63.patch75.15 KBclemens.tolboom
#59 interdiff-2084421-57-59.txt1.93 KBclemens.tolboom
#59 book-2084421-59.patch66.48 KBclemens.tolboom
#57 book-2084421.patch67.38 KBdawehner
#52 interdiff.txt7 KBdawehner
#52 book-2084421.patch69.98 KBdawehner
#46 interdiff.txt1.97 KBdawehner
#46 book-2084421-46.patch69.29 KBdawehner
#43 book-2084421-43.patch68.09 KBdawehner
#43 interdiff.txt5.58 KBdawehner
#42 interdiff.txt1.12 KBdawehner
#39 book-2084421.patch64.21 KBdawehner
#39 interdiff.txt2.5 KBdawehner
#32 2084421-increment-30-32.txt33.07 KBpwolanin
#32 book-2084421-32.patch63.75 KBpwolanin
#30 interdiff.txt8.55 KBdawehner
#30 book-2084421.patch44.02 KBdawehner
#26 2084421-increment-25-26.txt3.35 KBpwolanin
#26 book-2084421-26.patch42.46 KBpwolanin
#25 book-2084421-25.patch40.3 KBpwolanin
#23 book-2084421.patch43.03 KBdawehner
#23 interdiff.txt3.82 KBdawehner
#20 book-2084421.patch39.25 KBdawehner
#18 book-2084421.patch36.44 KBdawehner
#16 book-2084421.patch36.26 KBdawehner
#6 2084421-6.patch17.08 KBpwolanin
#2 2084421-2.patch4.64 KBpwolanin
#79 interdiff.txt1.18 KBdawehner
#79 book-2084421-79.patch78.64 KBdawehner
#77 book-2084421-76.patch78.65 KBpwolanin
#77 increment.txt9.37 KBpwolanin
#75 interdiff.txt1.49 KBdawehner
#75 book-2084421-75.patch73.33 KBdawehner
#71 interdiff.txt1.33 KBdawehner
#71 book-2084421-71.patch71.19 KBdawehner
#66 interdiff.txt2.51 KBdawehner
#64 2084421-book.patch73 KBdawehner
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

amateescu’s picture

A thousand times yes! I am (err.. was) doing the same thing with shortcuts over at #2021779-16: Decouple shortcuts from menu links.

pwolanin’s picture

Status: Active » Needs work
FileSize
4.64 KB

Here's a quick start at the possible schema change for book module. Ideally we need to decouple the tree-building code in menu.inc from their specificity to menu links.

For example, for book, we want to limit by bid instead of the faked-up menu name.

Berdir’s picture

Cleaning this up sounds awesome, this stuff drove me crazy in the Node BC removal issue. And it might help in the menu link NG issue too.

pwolanin’s picture

Discussed this a bit with fago and berdir this morning. We should potentially look at using the simple (non-configurable) entity reference field as a base and extending it so it has 3 properties: book, parent, weight

In refactoring this schema, it would likely make sense to go back to having the parent ID be a nid NOT a mlid, then we can rip the mlid field out too and use nid as the unique key in the table.

amateescu’s picture

That's the route I took with shortcuts as well, so +1 :)

pwolanin’s picture

FileSize
17.08 KB

A bit more hacking. This patch will still be totally non-functional.

After discussion with amateescu, this might be problematic to represent as a custom field - it's really NOT present per bundle, but rather on a node-by-node basis within the allowed bundles.

So, for now we should try to simplify it. We'll probably have to copy a simplified version of some of the menu code in, maybe to the book manager?

This starts to look more like the D5 version again (nid, pid), but keeping the materialized path optimizations.

kgoel’s picture

Title: Decouple book module schema from menu links » Phase 2 - Decouple book module schema from menu links

Updated title

BarisW’s picture

Would be nice to have this cleaned up, as we'd like to overhaul the menu system as well in #1777332: Replace theme_menu_link() and menu-tree.html.twig with a single Twig template. This would save us from making sure books can use the logics in menu.module.

pwolanin’s picture

made a meta issue so we can orgnize this into multiple steps https://drupal.org/node/2100575

pwolanin’s picture

Issue summary: View changes

Updated issue summary.

pwolanin’s picture

Issue summary: View changes

Updated issue summary.

dawehner’s picture

Issue summary: View changes
pwolanin’s picture

Issue summary: View changes
Issue tags: +beta blocker
webchick’s picture

Given that this isn't blocking a critical bug/task, and instead something that's really probably a feature (#2100575: [META] - Split book module from menu link), I'm not sure I agree with beta blocker on this.

pwolanin’s picture

@webchick - I think it's going to cause huge problems getting menu links finalized and cause ndedless performance regressions and complications for book if we don't do this.

xjm’s picture

Issue tags: -beta blocker +beta target

While I agree this is a good change to make and would be good to have in by beta 1, we could conceivably ship D8 without this change, and therefore it doesn't block beta. Tagging "beta target" instead.

pwolanin’s picture

@xjm - the menu link conversion won't be done without this (per ametescu), so I disagree.

dawehner’s picture

Status: Needs work » Needs review
Issue tags: +PHPUnit
FileSize
36.26 KB

Rerolled and started to actually try things out.
The current state is that you can save books though the navigation is not displayed properly yet.

Status: Needs review » Needs work

The last submitted patch, 16: book-2084421.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
36.44 KB

missed the getInfo method on the book manager test.

Status: Needs review » Needs work

The last submitted patch, 18: book-2084421.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
39.25 KB

Some more work, this will produce more failures, as now the tests don't fatal anymore.

Status: Needs review » Needs work

The last submitted patch, 20: book-2084421.patch, failed testing.

The last submitted patch, 20: book-2084421.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
3.82 KB
43.03 KB

Some work.

Status: Needs review » Needs work

The last submitted patch, 23: book-2084421.patch, failed testing.

pwolanin’s picture

Status: Needs work » Needs review
FileSize
40.3 KB

This is mostly a re-roll for a couple conflicts in BookBreadcrumbBuilder (maybe just whitespace?).

Also removes a debug() and I changed the access check in BookBreadcrumbBuilder to $parent_book->access('access', $this->account) instead of using the route access checker like:

$this->accessManager->checkNamedRoute('node.view', array('node' => $parent_book->id()), $this->account)

in fact, with the next patch we can maybe stop injecting the access manager if it's ok to use the entity access check.

pwolanin’s picture

FileSize
42.46 KB
3.35 KB

This patch greatly reduces the # of exceptions, but same number of fails.

Per discussion with tim.plunkett, the use of the entity access() method is probably more internally consistent than using the route check (though one could argue it's more correct) because the access check for nodes visible in the book block is done using a node access SQL query.

The last submitted patch, 25: book-2084421-25.patch, failed testing.

The last submitted patch, 26: book-2084421-26.patch, failed testing.

dawehner’s picture

+1 for using the entity checking. We are not longer bind our code to the menu/routing system but just offer some tree on top of nodes.

dawehner’s picture

FileSize
44.02 KB
8.55 KB

Just a bit more work.

The last submitted patch, 30: book-2084421.patch, failed testing.

pwolanin’s picture

FileSize
63.75 KB
33.07 KB

There was a lot of missing functionality that's in the menu links code - most of the book deletion/moving logic was wrong, suggesting the test coverage is mediocre.

so, a lot of this is pasted in and not fully tested yet.

The last submitted patch, 32: book-2084421-32.patch, failed testing.

xjm’s picture

@pwolanin suggested again that this should be a beta blocker for its impact on #1842858: [PP-1] Convert menu links to the new Entity Field API. Can anyone confirm whether or not this is a hard blocker for that issue? If so; it should be bumped to critical and a beta blocker; if not, it can remain a beta target (though a case could be made for it being major).

effulgentsia’s picture

Please correct me if I'm wrong, but I don't see how this can be a hard blocker to that issue. However, it may turn out that the patch needed in that issue could be smaller/better if this issue got done first.

amateescu’s picture

Agreed with #35, that issue got a green patch without this and only performance related problems stoppped it from getting in. So this is definitely not a hard blocker, but beta target and major priority makes sense indeed for the nice cleanup that it brings, and it does make that other patch easier.

Berdir’s picture

Yes, we were able to make that patch green without this, but that only works because we let book.module continue to work around the menu link entity APIs, which is going to conflict with at least two other criticals (using EFQ and making the menu_link storage translatable) and will prevent us from removing the array access BC layer, which need to remove.

effulgentsia’s picture

Priority: Normal » Critical
Issue tags: -beta target +beta blocker

I think #37 is a good justification for this being critical. And in that case, since this is a schema change, also a beta blocker.

dawehner’s picture

FileSize
2.5 KB
64.21 KB

There we go, this should make it green now.

Status: Needs review » Needs work

The last submitted patch, 39: book-2084421.patch, failed testing.

The last submitted patch, 39: book-2084421.patch, failed testing.

dawehner’s picture

FileSize
1.12 KB

This fixes the test, though opens a new one in the book tests.

dawehner’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
5.58 KB
68.09 KB

Fixed the test failures and reintroduced the book manager unit test.

webflo’s picture

Issue summary: View changes

Fixed issue summary

herom’s picture

Status: Needs review » Needs work

ahh, by the time the patch is picked up from the testbot queue, it won't apply anymore.

I have found two issues with this patch, through manual testing.

/core/modules/book/lib/Drupal/book/Form/BookOutlineForm.php
@@ 116 @@ public function submit(array $form, array &$form_state) {
     $book_link['menu_name'] = $this->bookManager->createMenuName($book_link['bid']);

createMenuName() is removed in this patch.

second, if a book page is created without adding to any book (- None -), then it is edited and " - Create a new book - " is selected from the outline form, it doesn't work and nothing is changed. this is because in BookManager->updateOutline(), the condition for creating a new book is inadequate:

    $new = empty($node->book['nid']);

here, after creating the initial book page, the 'nid' will have value, and the check wouldn't be correct anymore.

dawehner’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: +D8MA, +SprintWeekend2014
FileSize
69.29 KB
1.97 KB

Thank you for the manual test, this really uncovered an not-tested usecase.

This fixes the actual bug and introduced a new test for that bit.

clemens.tolboom’s picture

$ patch -p1 < book-2084421-46.patch
patching file core/modules/book/book.admin.inc
patching file core/modules/book/book.install
patching file core/modules/book/book.module
patching file core/modules/book/lib/Drupal/book/BookBreadcrumbBuilder.php
patching file core/modules/book/lib/Drupal/book/BookManager.php
Hunk #1 FAILED at 6.
Hunk #17 FAILED at 580.
Hunk #25 FAILED at 773.
3 out of 35 hunks FAILED -- saving rejects to file core/modules/book/lib/Drupal/book/BookManager.php.rej
patching file core/modules/book/lib/Drupal/book/Controller/BookController.php
patching file core/modules/book/lib/Drupal/book/Form/BookAdminEditForm.php
patching file core/modules/book/lib/Drupal/book/Form/BookRemoveForm.php
patching file core/modules/book/lib/Drupal/book/Plugin/Block/BookNavigationBlock.php
patching file core/modules/book/lib/Drupal/book/Tests/BookTest.php
patching file core/modules/book/tests/Drupal/book/Tests/BookManagerTest.php

clemens.tolboom’s picture

+++ b/core/modules/book/lib/Drupal/book/BookManager.php
@@ -151,16 +146,16 @@ public function getLinkDefaults($nid) {
+    return MENU_MAX_DEPTH - 1 - (($book_link['bid'] && $book_link['has_children']) ? $this->findChildrenRelativeDepth($book_link) : 0);

should be static::MENU_MAX_DEPTH

There are still several others.

BookManager.php:  const MENU_MAX_DEPTH = 9;
BookManager.php:    return MENU_MAX_DEPTH - 1 - (($book_link['bid'] && $book_link['has_children']) ? $this->findChildrenRelativeDepth($book_link) : 0);
BookManager.php:    while ($i <= MENU_MAX_DEPTH && $entity[$p]) {
BookManager.php:    for ($i = 1; $i <= MENU_MAX_DEPTH && $book_link["p$i"]; $i++) {
BookManager.php:        '#description' => $this->t('The parent page in the book. The maximum depth for a book and all child pages is !maxdepth. Some pages in the selected book may not be available as parents if selecting them would exceed this limit.', array('!maxdepth' => MENU_MAX_DEPTH)),
BookManager.php:          for ($i = 1; $i < MENU_MAX_DEPTH; $i++) {
BookManager.php:      for ($i = 1; $i <= MENU_MAX_DEPTH; $i++) {
BookManager.php:        for ($i = 1; $i <= MENU_MAX_DEPTH && $link["p$i"]; ++$i) {
BookManager.php:        for ($i = 1; $i <= MENU_MAX_DEPTH; ++$i) {

It maybe best to rename this right away in BOOK_MAX_DEPTH to make the distinction even clearer.

dawehner’s picture

Issue summary: View changes

The last submitted patch, 43: book-2084421-43.patch, failed testing.

clemens.tolboom’s picture

Status: Needs review » Needs work

As I guess #2084421-46: Phase 2 - Decouple book module schema from menu links will fail too needs work. See my previous (somewhat fuzzy) comments.

dawehner’s picture

Status: Needs work » Needs review
FileSize
69.98 KB
7 KB

Yeah that is indeed a good point, lets fix that as well as the rerole.

The last submitted patch, 46: book-2084421-46.patch, failed testing.

clemens.tolboom’s picture

When outlining an article I get two fatals

PHP Fatal error:  Class 'Drupal\\book\\Unicode' not found in /Users/clemens/Sites/drupal/d8/www/core/modules/book/lib/Drupal/book/BookManager.php on line 474, referer: http://drupal.d8/node/1/outline
PHP Fatal error:  Call to undefined method Drupal\\book\\BookManager::createMenuName() in /Users/clemens/Sites/drupal/d8/www/core/modules/book/lib/Drupal/book/Form/BookOutlineForm.php on line 116, referer: http://drupal.d8/node/1/outline
clemens.tolboom’s picture

\Drupal\book\BookManager misses import

use Drupal\Component\Utility\Unicode;

Is it possible to name the patch including the comment # please :)

Status: Needs review » Needs work

The last submitted patch, 52: book-2084421.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
67.38 KB

No idea what happened in the meantime.

clemens.tolboom’s picture

Status: Needs review » Needs work

I (still?) get an error when outlining at least a parent book itself

There was an error adding the post to the book.

 * Contains \Drupal\book\Form\BookOutlineForm.
...
  public function submit(array $form, array &$form_state) {
...
    if ($this->bookManager->updateOutline($this->entity)) {

only gets a FALSE and never a TRUE value from

   * @return bool
   *   TRUE if the menu link was saved; FALSE otherwise.
   */
  public function updateOutline(NodeInterface $node) {

and this does not produce a return value at all.

   * @return array
   *   The book data of that node.
   */
  public function saveBookLink(array $link, $new) {
clemens.tolboom’s picture

Attached patch fixes the errors around saving an outline manually. Let's see what the testbot thinks

clemens.tolboom’s picture

Status: Needs work » Needs review

(sigh)

clemens.tolboom’s picture

+++ b/core/modules/book/lib/Drupal/book/Form/BookOutlineForm.php
@@ -115,7 +115,7 @@ class BookOutlineForm extends ContentEntityFormController {
-      if ($this->entity->book['parent_mismatch']) {

Is parent_mismatch used at all? I think that it is not used anymore

dawehner’s picture

Just wanted to point out that my last patch missed the BookManagerTest again. The next person who creates a patch should merge that in

clemens.tolboom’s picture

FileSize
75.15 KB

Added BookManagerTest from #52

dawehner’s picture

FileSize
73 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, 64: 2084421-book.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
2.51 KB
71.18 KB
  • Failed on rerolling
  • The last patch from clemens contained some other issue, reverted these bits from the patch.

Status: Needs review » Needs work

The last submitted patch, 66: book-2084421-66.patch, failed testing.

clemens.tolboom’s picture

The interdiff from #66 contains

--- a/core/includes/file.inc
+++ b/core/includes/file.inc

I don't think these belong in here. The patch does not have these.

The test failure is cause by

Undefined index: options

.

dawehner’s picture

Status: Needs work » Needs review
FileSize
700 bytes
71.17 KB

Well, file.inc magically landed in a previous patch so I just removed it.

clemens.tolboom’s picture

There was an error adding the post to the book.

The error from #58 is back again.

So either I never fixed it or we have slippery patch handovers :)

(I cannot set this issues status to needs work ... aka https://drupal.org/node/2084421/edit seems broken)

dawehner’s picture

FileSize
71.19 KB
1.33 KB

@clemens.tolboom
Please better describe how to reproduce it. I really tried hard now to reproduce it, added quite some books and figured out some problems (not sure whether they are the same as you saw).

clemens.tolboom’s picture

The failure "There was an error adding the post to the book." is reproduced by

  1. Create a book node but do not create a book.
  2. Save book node
  3. Visit outline
  4. Select 'Create new book'
  5. Save

attached patch fixes the missing return TRUE needed for this to succeed. As we have not yet a test for this I tried to extend testBookOutline which unfortunately still fail.

Attached the full patch (including failing test as that's needed), inter-diff and failing test snippet.

Status: Needs review » Needs work

The last submitted patch, 72: book-2084421-72.patch, failed testing.

The last submitted patch, 72: book-2084421-72.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
73.33 KB
1.49 KB

There has been various problems on the test like accessing the wrong variable and expected behavior of JS in a php only enviroment.

pwolanin’s picture

  1. +++ b/core/modules/book/book.module
    @@ -662,17 +624,17 @@ function template_preprocess_book_navigation(&$variables) {
    -      $prev_href = url($prev['link_path']);
    +      $prev_href = url('node/' . $prev['nid']);
    

    minor - should switch this to \Drupal::url()

  2. +++ b/core/modules/book/lib/Drupal/book/BookManager.php
    @@ -304,61 +304,52 @@ public function updateOutline(NodeInterface $node) {
    +    // TODO: what happens here?
    +    elseif ($node->book['pid'] == -1) {
    +      $node->book['pid'] = $node->book['bid'];
         }
    

    The TODO here and just before it makes me worry a bit that something is being missed?

  3. +++ b/core/modules/book/lib/Drupal/book/BookManager.php
    @@ -868,41 +1032,27 @@ protected function _menu_tree_check_access(&$tree) {
    +      // @todo - load the nodes en-mass rather than individually.
    +      if (!$node) {
    ...
    +    if ($link['access']) {
    ...
    +        $node = $this->entityManager->getStorageController('node')->load($link['nid']);
    

    Should add some more comments here that we are using label(0 to get the translated node title?

pwolanin’s picture

FileSize
9.37 KB
78.65 KB

Trying to create a new book from an existing node I was getting:

Recoverable fatal error: Argument 2 passed to Drupal\book\BookManager::setParents() must be an array, null given, called in /Users/Shared/www/drupal-8/core/modules/book/lib/Drupal/book/BookManager.php on line 874 and defined in Drupal\book\BookManager->setParents() (line 963 of core/modules/book/lib/Drupal/book/BookManager.php).

This fixes that error, resolves some other bugs.

Points out that we need a test case to cover managing a book in an outline if it's in an outline, not a normally allowed tpye, and the user has the 'add content to books' perm.

Also, possible we should remove this case, or throw an exception:

elseif ($node->book['pid'] < 0) {

Status: Needs review » Needs work

The last submitted patch, 77: book-2084421-76.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
FileSize
78.64 KB
1.18 KB

Let's fix the tests.

clemens.tolboom’s picture

+++ b/core/modules/book/lib/Drupal/book/BookManager.php
@@ -810,6 +814,170 @@ public function bookTreeCollectNodeLinks(&$tree, &$node_links) {
+  /**
+   * @todo: what happens here?
+   *
+   * @param array $original
+   * @return type
+   */
+  protected function updateParentalStatus(array $original) {
+    if ($original['pid'] == 0) {

This function needs documentation filled in.

Furthermore I was wondering whether a Phase 3 is planned?

@pwolanin is a book not allowed to be in the outline?!?

dawehner’s picture

FileSize
21.14 KB
95.88 KB

Furthermore I was wondering whether a Phase 3 is planned?

Just one more? I would guess that we need at least 2 more one or even more. I would guess we don't have a good plan what exactly to do, beside the fact that we have a lot of things to do.

This function needs documentation filled in.

Filled in the documentation.

Maybe drop the max depth or change the table?

Well, if we want to drop max depth we have to change the table. Happily we can already swap out the book manager so you might be able to do it.

Allow contrib modules to overtake BookManager we need an interface? (https://drupal.org/project/book_made_simple)

Yeah, let's add one now, but let's try to not get crazy on this issue.

pwolanin’s picture

Yes, Phase 3+. Moving more of the code from the module to the manager would be important before we can define the interface.

I think we should wrap this up asap and move forward.

Status: Needs review » Needs work

The last submitted patch, 81: book-2084421-81.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review

81: book-2084421-81.patch queued for re-testing.

dawehner’s picture

Damn you random test failures!

dawehner’s picture

81: book-2084421-81.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 81: book-2084421-81.patch, failed testing.

Sutharsan’s picture

Status: Needs work » Needs review
FileSize
95.89 KB

Rerolled #81 patch.

dawehner’s picture

88: book-2084421-87.patch queued for re-testing.

pwolanin’s picture

pwolanin’s picture

88: book-2084421-87.patch queued for re-testing.

Xano’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

book-2084421-87.patch no longer applies.

error: patch failed: core/modules/book/book.module:5
error: core/modules/book/book.module: patch does not apply
error: patch failed: core/modules/book/lib/Drupal/book/BookManager.php:574
error: core/modules/book/lib/Drupal/book/BookManager.php: patch does not apply

Xano’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
94.47 KB

Re-roll.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 94: drupal_2084421_94.patch, failed testing.

herom’s picture

Status: Needs work » Needs review

seemed like testbot issue. lots of "Failed to write configuration file", "No such file or directory" errors.
94: drupal_2084421_94.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 94: drupal_2084421_94.patch, failed testing.

pwolanin’s picture

Assigned: Unassigned » pwolanin

Seems like a problem with cache not being cleared when saving book links, but so far have not got it working right.

Also found a bunch of other code to remove and comments to update o top of my own re-roll.

pwolanin’s picture

Status: Needs work » Needs review
FileSize
94.96 KB
7.49 KB
95.83 KB

ok, posting my own re-roll (should be like #94) plus fixes for caching and other fixes, plus the incremental diff of those 2.

The last submitted patch, 100: book-2084421-reroll-99.patch, failed testing.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

It was RTBC before and we could continue and increase the patch size over 100k but let's try to stop at some point (now).

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

book-2084421-100.patch no longer applies.

error: patch failed: core/modules/book/lib/Drupal/book/BookManager.php:518
error: core/modules/book/lib/Drupal/book/BookManager.php: patch does not apply

Berdir’s picture

Status: Needs work » Needs review
FileSize
95.67 KB
943 bytes

Re-roll, only conflict was a Note on bookTreeOutput() that was changed to a @todo and in this patch moved from BookManager to the interface.

dsnopek’s picture

Status: Needs review » Reviewed & tested by the community

Was RTBC before re-roll and tests pass so setting it back.

Berdir’s picture

104: book-2084421-104.patch queued for re-testing.

catch’s picture

Didn't do a full review yet.

I was a bit concerned when I saw the mat path stuff copied from menu links, but there's not actually that much extra code copied, and there's the option to factor that into something shareable later. Seems OK in general but not looked in depth enough to be comfortable committing.

One obvious bug in the patch:

+++ b/core/modules/book/book.module
@@ -434,14 +418,14 @@ function book_children($book_link) {
+  if (TRUE || $book_link['has_children']) {
rlmumford’s picture

Status: Reviewed & tested by the community » Needs work
clemens.tolboom’s picture

Status: Needs work » Needs review
FileSize
94.19 KB

Fixed the remark of @catch #107

[edit]user-1 can do more then others so
but I noticed I can add Page and Article on node/add/page|article having made Article Parent book while http://drupal.d8/admin/structure/book/settings denied those types.

[/edit]

clemens.tolboom’s picture

Status: Needs review » Needs work
FileSize
26.64 KB

Having added the following book structure

#0    Article for book
#1        Basic Page 1
#2        Page 2 for book
#3        Page 3 for book

It is possible to navigate from #3 to #2 (previous) and #0 (up) but not from #0 to #1 on their node pages.

This looks like a bug to me.

pwolanin’s picture

Status: Needs work » Needs review
FileSize
452 bytes
95.73 KB

@catch - yeah. We copied a bunch since core doesn't have any generic hierarchy code and menu links is transforming into entity stuff. amateescu had ideas about creating a kind of hierarchy field for menu links. If that happens we might be able to leverage it.

sorry about that bug - obviously a lot of hacking to just get this working separate from menu links, and then we'll have follow-up issues to make it a better interface and nicer code.

pwolanin’s picture

ugh, thanks d.o.. guess cross-posts are messy

The last submitted patch, 109: book-2084421-109.patch, failed testing.

clemens.tolboom’s picture

@pwolanin please explain #112

In #110 I set issue to "needs work". Did you fixed that one too?

dawehner’s picture

@clemens.tolboom
Can you please test whether the behavior works in Drupal 8 HEAD?

pwolanin’s picture

@clemens.tolboom - I was seeing that before the caching fix, but I don't see it now. I just set up the same structure and it seems fine.

pwolanin’s picture

Status: Needs review » Needs work

I'm seeing some bugs yet - the

  • representing a page with children still has the leaf class

    It should have the collapsed or expanded class. Also the book navigation isn't correct, though I don't see the same error as clemens.tolboom

  • pwolanin’s picture

    Ok, the bug seems to be mostly (or totally) that the has_children flag is not getting set right. Not sure why tests are not finding that.

    Also, seems liek there is still a caching issue. I sometimes see the kind of bug with prev links, but can resolve it with a cache clear.

    pwolanin’s picture

    Status: Needs work » Needs review
    FileSize
    97.04 KB
    11.33 KB
    100.38 KB

    Here is a new patch that just adds test cases. These should cause multiple failures.
    Then a further patch that adds fixes for the problems I found, and the increment from my -109 to that

    Status: Needs review » Needs work

    The last submitted patch, 119: book-2084421-119-with-fixes.patch, failed testing.

    The last submitted patch, 119: book-2084421-119-only-tests.patch, failed testing.

    pwolanin’s picture

    Status: Needs work » Needs review
    FileSize
    97.03 KB
    11.33 KB
    100.37 KB

    Re-rolls of the last set of patches for #collapsed and language() changes.

    The last submitted patch, 122: book-2084421-122-only-tests.patch, failed testing.

    Status: Needs review » Needs work

    The last submitted patch, 122: book-2084421-122-with-fixes.patch, failed testing.

    pwolanin’s picture

    Status: Needs work » Needs review
    FileSize
    616 bytes
    100.42 KB

    Silly - looks like weight wasn't set, so let's combine in the link defaults. Also I guess the ImageFieldDisplayTest was broken HEAD.

    YesCT’s picture

    reading through this.
    fixing some api docs gates and some nits.
    might have some questions...
    patch coming.

    YesCT’s picture

    Issue tags: -Needs reroll
    FileSize
    101.43 KB
    18.13 KB
    1. +++ b/core/modules/book/book.module
      @@ -302,14 +284,14 @@ function book_form_update($form, $form_state) {
      -  if (!isset($flat[$book_link['mlid']])) {
      -    // Call bookTreeAllData() to take advantage of the menu system's caching.
      
      @@ -345,31 +325,34 @@ function _book_flatten_menu($tree, &$flat) {
             return $data['link'];
      
      @@ -746,6 +715,27 @@ function template_preprocess_book_node_export_html(&$variables) {
      + * @param $variables
      + *   An associative array containing:
      + *   - element: Structured array data for a book link.
      

      type, array.

    2. +++ b/core/modules/book/book.module
      @@ -746,6 +715,27 @@ function template_preprocess_book_node_export_html(&$variables) {
      + */
      +function theme_book_link(array $variables) {
      +  $element = $variables['element'];
      

      needs public/private specified (though many others in this file are missing, but since this is new code, should be done right).
      [edit: uh, no, this in in .module, not in a class]

    3. +++ b/core/modules/book/lib/Drupal/book/Access/BookNodeIsRemovableAccessCheck.php
      @@ -21,17 +22,17 @@ class BookNodeIsRemovableAccessCheck implements AccessInterface {
      -   * @var \Drupal\book\BookManager
      +   * @var BookManagerInterface
      

      classes in comments should be use full namespace path. https://drupal.org/node/1353118

    4. +++ b/core/modules/book/lib/Drupal/book/BookManager.php
      @@ -16,10 +18,12 @@
      -/**
      - * Book Manager Service.
      - */
      -class BookManager {
      +class BookManager implements BookManagerInterface {
      

      oops. doc block should remain.
      though maybe a better description than Defines a book manager.

    5. +++ b/core/modules/book/lib/Drupal/book/BookManager.php
      @@ -91,23 +89,20 @@ protected function loadBooks() {
      +      // @todo: Sort by weight and translated title.
       
      +      // @todo: use route name for links, not system path.
             foreach ($book_links as $link) {
      

      This issue might still be in an early phase of "needs review", so these might be going to be resolved in this issue. (although it has been rtbc a few times...)

      But, if we dont intend to fix these in this issue, we should open issues for them and link the issues in the comment.

    6. +++ b/core/modules/book/lib/Drupal/book/BookManager.php
      @@ -517,104 +424,69 @@ public function getTableOfContents($bid, $depth_limit, array $exclude = array())
      +    // Use $nid as a flag for whether the data being loaded is for the whole tree.
      +    $nid = isset($link['nid']) ? $link['nid'] : 0;
      +    // Generate a cache ID (cid) specific for this $bid, $link, $language, and depth.
      +    $cid = 'book-links:' . $bid . ':all:' . $nid . ':' . $language_interface->id . ':' . (int) $max_depth;
      

      since editing these comments anyway, also wrapping them to 80 chars.

    7. +++ b/core/modules/book/lib/Drupal/book/BookManager.php
      @@ -809,13 +674,198 @@ public function bookTreeCollectNodeLinks(&$tree, &$node_links) {
      +
      +  protected function moveChildren(array $link, array $original) {
      +    $query = $this->connection->update('book');
      +
      

      I can't actually figure out what this does. But started the docs anyway. Please correct the details.

        /**
         * Moves children from the original parent to the updated link.
         * 
         * @param array $link
         *   The link being saved.
         * @param array $original
         *   The original parent of $link.
         */
      
    8. +++ b/core/modules/book/lib/Drupal/book/BookManager.php
      @@ -809,13 +674,198 @@ public function bookTreeCollectNodeLinks(&$tree, &$node_links) {
      +   * @param array $link
      +   *   The book which parent we want to update.
      ...
      +   * @param array $original
      +   *   The book which parent we want to update.
      

      the argument is not the parent, but the book whose parents we want to upcdate, right?

    9. +++ b/core/modules/book/lib/Drupal/book/BookManager.php
      @@ -809,13 +674,198 @@ public function bookTreeCollectNodeLinks(&$tree, &$node_links) {
      +    $query->fields(array('has_children' => 1))
      

      should this be setting it to true?

    10. +++ b/core/modules/book/lib/Drupal/book/BookManager.php
      @@ -809,13 +674,198 @@ public function bookTreeCollectNodeLinks(&$tree, &$node_links) {
      +   * This method is mostly called when a book is moved/created etc. so we want
      +   * to update the has_children flag of the parent node.
      

      I don't think this applies to creating. It assumes original is NOT a child any longer of it's original parents.

      This makes sense for a deleted link.. but for a moved link, does it assume the children of the moved link do not move with it?

    11. +++ b/core/modules/book/lib/Drupal/book/BookManager.php
      @@ -809,13 +674,198 @@ public function bookTreeCollectNodeLinks(&$tree, &$node_links) {
      +    // Check if at least one child exists in the table.
      +    $parent_has_children = $this->connection->select('book', 'b')
      

      is this checking if $original was the child or at least something else in the book?

      Or if this link in the book *had* children, and the parent of those children needs to be updated?

    12. +++ b/core/modules/book/lib/Drupal/book/BookManager.php
      @@ -809,13 +674,198 @@ public function bookTreeCollectNodeLinks(&$tree, &$node_links) {
      +      ->condition('bid', $original['bid'])
      +      ->condition('pid', $original['pid'])
      +      ->condition('nid', $original['nid'], '<>')
      

      I'm not sure this is correct.

      Maybe that should be ->condition('pid', $original['nid'])

      to check if the nid was a parent of anything.

      Does this actually return the number of children?

    13. +++ b/core/modules/book/lib/Drupal/book/BookManager.php
      @@ -809,13 +674,198 @@ public function bookTreeCollectNodeLinks(&$tree, &$node_links) {
      +    $parent_has_children = ((bool) $parent_has_children) ? 1 : 0;
      +    $query = $this->connection->update('book');
      +    $query->fields(array('has_children' => $parent_has_children))
      +        ->condition('nid', $original['pid']);
      +    return $query->execute();
      

      if the original had children, the there is no need to execute the query to update the parent, cause the has_children value should be remaining the same (true), right?

    14. +++ b/core/modules/book/lib/Drupal/book/BookManagerInterface.php
      @@ -0,0 +1,246 @@
      +   * @return
      +   *   An array of all books.
      

      I made the return type array, but I wonder if we can be more specific, like an array of bookmanagers (interfaces)?

    15. +++ b/core/modules/book/lib/Drupal/book/BookManagerInterface.php
      @@ -0,0 +1,246 @@
      +   * @param $link
      +   *   A fully loaded menu link.
      +   *
      +   * @return
      +   *   A subtree of menu links in an array, in the order they should be rendered.
      +   */
      +  public function bookMenuSubtreeData($link);
      

      this was already called bookMenu... before this issue, but since this is about decoupling menu and book, I didn't expect to see menu so much in the api docs on this method.

    16. +++ b/core/modules/book/lib/Drupal/book/Form/BookAdminEditForm.php
      @@ -7,6 +7,8 @@
      +use \Drupal\book\BookManager;
      +use Drupal\book\BookManagerInterface;
      

      \ not needed... actually phpstorm says that class is not used. taking it out.

    17. +++ b/core/modules/book/lib/Drupal/book/Form/BookOutlineForm.php
      @@ -7,6 +7,7 @@
      +use Drupal\book\BookManagerInterface;
       use Drupal\Core\Entity\ContentEntityFormController;
       use Drupal\Core\Entity\EntityManagerInterface;
       use Drupal\book\BookManager;
      

      dont need the BookManager anymore, since using the Interface.

    18. +++ b/core/modules/book/tests/Drupal/book/Tests/BookManagerTest.php
      @@ -0,0 +1,127 @@
      + * Tests the book manager.
      + *
      + * @coversDefaultClass \Drupal\book\BookManager
      

      https://drupal.org/node/2057905
      also recommends @group Drupal and the module

    Patch did apply, removing the needs reroll tag.
    I read (almost) all the lines.
    I feel like I need to read this through again before I can understand it.
    I did not test this manually.
    I fixed some nits, and some api docs core gates stuff (types).
    I changed a variable name to make code clearer.
    I added/changed (corrected) some comments.

    Before patch:
    ./vendor/bin/phpunit --group Book --strict
    OK (4 tests, 16 assertions)

    After patch:
    OK (7 tests, 25 assertions)

    Status: Needs review » Needs work

    The last submitted patch, 127: book-2084421-127.patch, failed testing.

    YesCT’s picture

    Status: Needs work » Needs review
    FileSize
    101.42 KB
    452 bytes

    duh, functions in .module are not methods (public/protected) in a class.

    Status: Needs review » Needs work

    The last submitted patch, 129: book-2084421-129.patch, failed testing.

    YesCT’s picture

    Status: Needs work » Needs review
    FileSize
    101.42 KB
    745 bytes

    sorry, missed one.

    dawehner’s picture

    Status: Needs review » Reviewed & tested by the community

    +1 for all the changes. Thank you!

    dawehner’s picture

    FileSize
    101.41 KB

    Just another reroll, here is nothing to see.

    alexpott’s picture

    Title: Phase 2 - Decouple book module schema from menu links » Change record: Phase 2 - Decouple book module schema from menu links
    Status: Reviewed & tested by the community » Active
    Issue tags: +Needs change record, +Missing change record

    Committed 0ca87db and pushed to 8.x. Thanks!

    Let's get a change record in place.

    cosmicdreams’s picture

    I found some documentation flaws regarding BookManagerInterface after this patch landed. Should I open up a follow up to fix them (only 2 issues where the full path wasn't used when documenting the interface.)?

    xjm’s picture

    @cosmicdreams, yes, please open a followup and link it here.

    cosmicdreams’s picture

    xjm’s picture

    Thanks!

    dawehner’s picture

    To be honest I don't really know what to write about as most changes are sorta internal only ... https://drupal.org/node/2208415

    xjm’s picture

    Status: Active » Needs work

    Thanks!

    Internal or not, I think the change record needs to explicitly list D7 functions (etc.) removed and their D8 replacements.

    alexpott’s picture

    Since my commit without a change notice has caused some discussion I'd like to point out that in our policy there is latitude for committer discretion in the case of critical patches. This patch had to be rerolled a number of times and is a beta blocker so I think it passed that test.

    Berdir’s picture

    I agree with @dawehner, there are no API functions involved that we can document in a useful way, most are hook implementations and lots of changes in the BookManager and forms and form alters. I accidently created a duplicate of @dawehner's change reocrd but it was essentially the same as his (I missed that he created one above).

    So, I just fixed the project and issue reference (how did you do that!? ;)) and made the BookManagerInterface a link to the API documentation.

    There is no before/after code examples that would be useful IMHO.

    I did notice that this patch re-adds a book_library_info(), which should be removed. Created https://drupal.org/node/2208669 for that.

    clemens.tolboom’s picture

    Is there a Phase 3 follow up to come?

    xjm’s picture

    Thanks @Berdir and @dawehner. I deleted the duplicate change record. I'm trying to figure out if there were other, earlier BC breaks for the book module that didn't get change records? https://api.drupal.org/api/drupal/7/search/book and https://api.drupal.org/api/drupal/8/search/book are very different.

    Do we need to update https://drupal.org/node/1914008 as well, last section? https://drupal.org/node/1800686 has a lot of book examples but on a quick skim none of them looked relevant.

    xjm’s picture

    Status: Needs work » Needs review
    dawehner’s picture

    xjm’s picture

    Title: Change record: Phase 2 - Decouple book module schema from menu links » Phase 2 - Decouple book module schema from menu links
    Assigned: pwolanin » Unassigned
    Status: Needs review » Fixed
    Issue tags: -Needs change record, -Missing change record

    Discussed with @dawehner and @longwave. Unlike Taxonomy, Book in D7 didn't really have a public API to speak of... just lots of array manipulation and re-use of the menu API, which is why we have this issue in the first place. In general, people will need to re-do alters to render arrays all over the place anyway because we don't really document these with change records. So with those change record updates I think we can call this fixed. Phew. :) Thanks everyone!

    Status: Fixed » Closed (fixed)

    Automatically closed - issue fixed for 2 weeks with no activity.