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.
Related Issues
Comment | File | Size | Author |
---|---|---|---|
#133 | book_manager-2084421-133.patch | 101.41 KB | dawehner |
#131 | interdiff-2084421-127-131.txt | 745 bytes | YesCT |
#131 | book-2084421-131.patch | 101.42 KB | YesCT |
#129 | interdiff-2084421-127-129.txt | 452 bytes | YesCT |
#129 | book-2084421-129.patch | 101.42 KB | YesCT |
Comments
Comment #1
amateescu CreditAttribution: amateescu commentedA thousand times yes! I am (err.. was) doing the same thing with shortcuts over at #2021779-16: Decouple shortcuts from menu links.
Comment #2
pwolanin CreditAttribution: pwolanin commentedHere'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.
Comment #3
BerdirCleaning 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.
Comment #4
pwolanin CreditAttribution: pwolanin commentedDiscussed 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.
Comment #5
amateescu CreditAttribution: amateescu commentedThat's the route I took with shortcuts as well, so +1 :)
Comment #6
pwolanin CreditAttribution: pwolanin commentedA 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.
Comment #7
kgoel CreditAttribution: kgoel commentedUpdated title
Comment #8
BarisW CreditAttribution: BarisW commentedWould 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.
Comment #9
pwolanin CreditAttribution: pwolanin commentedmade a meta issue so we can orgnize this into multiple steps https://drupal.org/node/2100575
Comment #9.0
pwolanin CreditAttribution: pwolanin commentedUpdated issue summary.
Comment #9.1
pwolanin CreditAttribution: pwolanin commentedUpdated issue summary.
Comment #10
dawehnerComment #11
pwolanin CreditAttribution: pwolanin commentedComment #12
webchickGiven 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.
Comment #13
pwolanin CreditAttribution: pwolanin commented@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.
Comment #14
xjmWhile 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.
Comment #15
pwolanin CreditAttribution: pwolanin commented@xjm - the menu link conversion won't be done without this (per ametescu), so I disagree.
Comment #16
dawehnerRerolled and started to actually try things out.
The current state is that you can save books though the navigation is not displayed properly yet.
Comment #18
dawehnermissed the getInfo method on the book manager test.
Comment #20
dawehnerSome more work, this will produce more failures, as now the tests don't fatal anymore.
Comment #23
dawehnerSome work.
Comment #25
pwolanin CreditAttribution: pwolanin commentedThis 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:in fact, with the next patch we can maybe stop injecting the access manager if it's ok to use the entity access check.
Comment #26
pwolanin CreditAttribution: pwolanin commentedThis 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.
Comment #29
dawehner+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.
Comment #30
dawehnerJust a bit more work.
Comment #32
pwolanin CreditAttribution: pwolanin commentedThere 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.
Comment #34
xjm@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).
Comment #35
effulgentsia CreditAttribution: effulgentsia commentedPlease 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.
Comment #36
amateescu CreditAttribution: amateescu commentedAgreed 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.
Comment #37
BerdirYes, 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.
Comment #38
effulgentsia CreditAttribution: effulgentsia commentedI think #37 is a good justification for this being critical. And in that case, since this is a schema change, also a beta blocker.
Comment #39
dawehnerThere we go, this should make it green now.
Comment #42
dawehnerThis fixes the test, though opens a new one in the book tests.
Comment #43
dawehnerFixed the test failures and reintroduced the book manager unit test.
Comment #44
webflo CreditAttribution: webflo commentedFixed issue summary
Comment #45
herom CreditAttribution: herom commentedahh, 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.
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:here, after creating the initial book page, the 'nid' will have value, and the check wouldn't be correct anymore.
Comment #46
dawehnerThank 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.
Comment #47
clemens.tolboom$ 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
Comment #48
clemens.tolboomshould be static::MENU_MAX_DEPTH
There are still several others.
It maybe best to rename this right away in BOOK_MAX_DEPTH to make the distinction even clearer.
Comment #49
dawehnerComment #51
clemens.tolboomAs I guess #2084421-46: Phase 2 - Decouple book module schema from menu links will fail too needs work. See my previous (somewhat fuzzy) comments.
Comment #52
dawehnerYeah that is indeed a good point, lets fix that as well as the rerole.
Comment #54
clemens.tolboomWhen outlining an article I get two fatals
Comment #55
clemens.tolboom\Drupal\book\BookManager misses import
Is it possible to name the patch including the comment # please :)
Comment #57
dawehnerNo idea what happened in the meantime.
Comment #58
clemens.tolboomI (still?) get an error when outlining at least a parent book itself
only gets a FALSE and never a TRUE value from
and this does not produce a return value at all.
Comment #59
clemens.tolboomAttached patch fixes the errors around saving an outline manually. Let's see what the testbot thinks
Comment #60
clemens.tolboom(sigh)
Comment #61
clemens.tolboomIs parent_mismatch used at all? I think that it is not used anymore
Comment #62
dawehnerJust wanted to point out that my last patch missed the BookManagerTest again. The next person who creates a patch should merge that in
Comment #63
clemens.tolboomAdded BookManagerTest from #52
Comment #64
dawehnerRerolled.
Comment #66
dawehnerComment #68
clemens.tolboomThe interdiff from #66 contains
I don't think these belong in here. The patch does not have these.
The test failure is cause by
.
Comment #69
dawehnerWell, file.inc magically landed in a previous patch so I just removed it.
Comment #70
clemens.tolboomThe 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)
Comment #71
dawehner@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).
Comment #72
clemens.tolboomThe failure "There was an error adding the post to the book." is reproduced by
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.
Comment #75
dawehnerThere has been various problems on the test like accessing the wrong variable and expected behavior of JS in a php only enviroment.
Comment #76
pwolanin CreditAttribution: pwolanin commentedminor - should switch this to \Drupal::url()
The TODO here and just before it makes me worry a bit that something is being missed?
Should add some more comments here that we are using label(0 to get the translated node title?
Comment #77
pwolanin CreditAttribution: pwolanin commentedTrying to create a new book from an existing node I was getting:
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:
Comment #79
dawehnerLet's fix the tests.
Comment #80
clemens.tolboomThis 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?!?
Comment #81
dawehnerJust 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.
Filled in the documentation.
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.
Yeah, let's add one now, but let's try to not get crazy on this issue.
Comment #82
pwolanin CreditAttribution: pwolanin commentedYes, 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.
Comment #84
dawehner81: book-2084421-81.patch queued for re-testing.
Comment #85
dawehnerDamn you random test failures!
Comment #86
dawehner81: book-2084421-81.patch queued for re-testing.
Comment #88
Sutharsan CreditAttribution: Sutharsan commentedRerolled #81 patch.
Comment #89
dawehner88: book-2084421-87.patch queued for re-testing.
Comment #90
pwolanin CreditAttribution: pwolanin commentedComment #91
pwolanin CreditAttribution: pwolanin commented88: book-2084421-87.patch queued for re-testing.
Comment #92
XanoLooks good to me.
Comment #93
alexpottbook-2084421-87.patch no longer applies.
Comment #94
XanoRe-roll.
Comment #95
dawehnerBack to RTBC.
Comment #97
herom CreditAttribution: herom commentedseemed 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.
Comment #99
pwolanin CreditAttribution: pwolanin commentedSeems 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.
Comment #100
pwolanin CreditAttribution: pwolanin commentedok, posting my own re-roll (should be like #94) plus fixes for caching and other fixes, plus the incremental diff of those 2.
Comment #102
dawehnerIt was RTBC before and we could continue and increase the patch size over 100k but let's try to stop at some point (now).
Comment #103
alexpottbook-2084421-100.patch no longer applies.
Comment #104
BerdirRe-roll, only conflict was a Note on bookTreeOutput() that was changed to a @todo and in this patch moved from BookManager to the interface.
Comment #105
dsnopekWas RTBC before re-roll and tests pass so setting it back.
Comment #106
Berdir104: book-2084421-104.patch queued for re-testing.
Comment #107
catchDidn'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:
Comment #108
rlmumfordComment #109
clemens.tolboomFixed 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]
Comment #110
clemens.tolboomHaving added the following book structure
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.
Comment #111
pwolanin CreditAttribution: pwolanin commented@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.
Comment #112
pwolanin CreditAttribution: pwolanin commentedugh, thanks d.o.. guess cross-posts are messy
Comment #114
clemens.tolboom@pwolanin please explain #112
In #110 I set issue to "needs work". Did you fixed that one too?
Comment #115
dawehner@clemens.tolboom
Can you please test whether the behavior works in Drupal 8 HEAD?
Comment #116
pwolanin CreditAttribution: pwolanin commented@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.
Comment #117
pwolanin CreditAttribution: pwolanin commentedI'm seeing some bugs yet - the
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
Comment #118
pwolanin CreditAttribution: pwolanin commentedOk, 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.
Comment #119
pwolanin CreditAttribution: pwolanin commentedHere 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
Comment #122
pwolanin CreditAttribution: pwolanin commentedRe-rolls of the last set of patches for #collapsed and language() changes.
Comment #125
pwolanin CreditAttribution: pwolanin commentedSilly - looks like weight wasn't set, so let's combine in the link defaults. Also I guess the ImageFieldDisplayTest was broken HEAD.
Comment #126
YesCT CreditAttribution: YesCT commentedreading through this.
fixing some api docs gates and some nits.
might have some questions...
patch coming.
Comment #127
YesCT CreditAttribution: YesCT commentedtype, array.
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]
classes in comments should be use full namespace path. https://drupal.org/node/1353118
oops. doc block should remain.
though maybe a better description than Defines a book manager.
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.
since editing these comments anyway, also wrapping them to 80 chars.
I can't actually figure out what this does. But started the docs anyway. Please correct the details.
the argument is not the parent, but the book whose parents we want to upcdate, right?
should this be setting it to true?
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?
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?
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?
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?
I made the return type array, but I wonder if we can be more specific, like an array of bookmanagers (interfaces)?
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.
\ not needed... actually phpstorm says that class is not used. taking it out.
dont need the BookManager anymore, since using the Interface.
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)
Comment #129
YesCT CreditAttribution: YesCT commentedduh, functions in .module are not methods (public/protected) in a class.
Comment #131
YesCT CreditAttribution: YesCT commentedsorry, missed one.
Comment #132
dawehner+1 for all the changes. Thank you!
Comment #133
dawehnerJust another reroll, here is nothing to see.
Comment #134
alexpottCommitted 0ca87db and pushed to 8.x. Thanks!
Let's get a change record in place.
Comment #135
cosmicdreams CreditAttribution: cosmicdreams commentedI 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.)?
Comment #136
xjm@cosmicdreams, yes, please open a followup and link it here.
Comment #137
cosmicdreams CreditAttribution: cosmicdreams commentedAdd the follow up issue.
Comment #138
xjmThanks!
Comment #139
dawehnerTo be honest I don't really know what to write about as most changes are sorta internal only ... https://drupal.org/node/2208415
Comment #140
xjmThanks!
Internal or not, I think the change record needs to explicitly list D7 functions (etc.) removed and their D8 replacements.
Comment #141
alexpottSince 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.
Comment #142
BerdirI 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.
Comment #143
clemens.tolboomIs there a Phase 3 follow up to come?
Comment #144
xjmThanks @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.
Comment #145
xjmComment #146
dawehnerA couple of changes:
Comment #147
xjmDiscussed 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!
Comment #148
pwolanin CreditAttribution: pwolanin commentedHere are 2 follow-ups:
#2208395: Follow up: Documentation issues with BookManagerInterface
#2209025: Phase 3 - Make the BookManager interface more coherent, move more code out of book.module
Please add whatever more is needed to the meta issue:
#2100575: [META] - Split book module from menu link
Related:
#2207893: Convert menu tree building to a service.
Comment #149
pwolanin CreditAttribution: pwolanin commentedMore little follow-ups:
#2209029: Follow-up: clean up use statements in book module code
#2209035: Remove remaining/stray menu_link references from book module code