Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Step:
1.Create an any type of content.
2.Select a book at Book Outline block.
3.Select a Parent item (Not the top-level one) .
4.Save.
Expect:
Set the Parent item correctly,
Wrong:
Always save the parent item as top-level book page.
Comment | File | Size | Author |
---|---|---|---|
#10 | book_unpublished_patch_760102-10.patch | 4.27 KB | das-peter |
Comments
Comment #1
jpmckinney CreditAttribution: jpmckinney commentedIs #761648: Menu D6->D7 upgrade doesn't maintain node-menu configuration (f.k.a.: Menu items disappear after upgrade or manual menu entry) possibly related?
Comment #2
wjaspers CreditAttribution: wjaspers commentedIts a problem with the way books deal with Published/Unpublished nodes in the outline.
If the Top-Level book is Unpublished, its impossible to add anything to it.
If the Next-Highest-Level content is Unpublished, its impossible to add any content to its outline.
If the Top-Level book is Published, but the Next-Highest-Level content is unpublished, you can add content to the book, but not to the section you want.
Around line 368.... you should see:
$query->condition('n.status', 1);
This condition enforces outline settings to only work when the parent book is published--which is a royal pain if you're trying to construct a book without end-users seeing it or any of its contents.
Disabling this line solves (at least for me it has) the problem of the outline not working correctly at all; but still leaves the question of how to put content into an outline beneath unpublished content.
Comment #3
Michael-IDA CreditAttribution: Michael-IDA commentedShould this bug be expanded to book.module needs to correctly handle unpublished content?
Additional bug:
On page /admin/content/book/NN, unpublished child nodes do not display for rearrangement.
Expected Behavior:
- All book nodes should be displayed and re-arrangeable on the book's "edit order and titles" page.
- Nodes should be flagged published/unpublished.
- - Feature request: Include a column of check boxes on that page for "Published"
Comment #4
Michael-IDA CreditAttribution: Michael-IDA commentedgoing bigger picture, as you should be able to "construct a book without end-users seeing it or any of its contents."
Comment #5
soulston CreditAttribution: soulston commentedThis is a very basic start to look at how to achieve this. I need to be able to create a book that is unpublished and then add nodes from other content types to that book. Essentially it adds a status to the array so that it can be queried elsewhere:
I realise that there are issues with hacking the book_get_book function in this way as it potentially circumnavigates the unpublished permissions but it's a start. I did try to achieve this with hook_query_alter() but with no luck. From what I can see this function is used here:
The other changes are mainly for the admin screens to output some helper text to tell you that a book is indeed unpublished.
Comment #6
wjaspers CreditAttribution: wjaspers commentedI'm not sure that I'd use isset().
Instead, you can check if empty($book['status']). Any value above 0 will return false, and we can safely assume the book is "published".
Added tab character. Remove.
Added tab character. Remove.
Your patch introduces commented out development only code. Please remove.
Otherwise, this looks good.
Just a thought:
In my honest opinion, i'd think that being able to view/access unpublished books/content therein is OK, so long as you have permission to view the content type. Therefore, the administrative tools for books should be ignorant of status. Only the publish state really matters to the end-visitors. Comments?
Comment #7
soulston CreditAttribution: soulston commentedThanks for the feedback. I fixed these items and also added a clause in the book.pages.inc to pick up on the status value.
One other thing that I was not sure how to handle is the blank parent item when you have a child page that features in an unpublished book - see attached image.
Comment #8
marcingy CreditAttribution: marcingy commentedThis needs to be fixed in d8 first and then backported.
Comment #9
das-peter CreditAttribution: das-peter commentedUpdated patch for D7...
Comment #10
das-peter CreditAttribution: das-peter commentedSome more adjustments.
And I should outline what I've changed.
Contrary to the patch from #7 and before this patch won't change the default behaviour of
book_get_books()
but it introduces a new parameter to define whether unpublished nodes shall be included in the return or not.All locations that want to get unpublished nodes as well have to change the call to
book_get_books()
.Comment #11
Andy_D CreditAttribution: Andy_D commentedPatch #7 fixed the issue for me. Still unable to select a Parent Item or reorder the book.
I did see errors linked to the theme_book_title_link function so added a check:
Comment #12
matason CreditAttribution: matason commentedIn response to @soulston and the point about the parent item dropdown remaining empty, I think this occurs because menu_build_tree() is called and in turn menu_tree_check_access() which checks the current users access to each node link, if you look at the code in that function you see that status = 1 condition which of course fails...
Comment #13
dtamajon CreditAttribution: dtamajon commentedThe patch is not working properly when there are no books created, or non published.
I purpose the next modification on return values, in book_get_books:
An array empty is needed to allow the foreach working in _book_add_form_elements, where a direct all to book_get_books is done from the foreach itself.
Comment #14
moulie415 CreditAttribution: moulie415 commentedRookie here needing help!!! This patch removes the table of contents for my books can anyone help me fix this?
Comment #15
osopolarI was wondering if there is no workaround for D7. Maybe the module view_unpublished could be helpful, but it is limited to TableSort queries, see #2558295: Would it be save to remove the condition check "is tablesort query" from the query alter hook?
Comment #16
ladybug_3777 CreditAttribution: ladybug_3777 commentedosopolar, I've been using the hidden_nodes and book_helper modules to handle this problem. So far it's working out really well! You might want to take a look and see if they help you too.
https://www.drupal.org/project/hidden_nodes
https://www.drupal.org/project/book_helper
Hidden nodes basically allows you to have a page be "published" but not displayed to the public, so that allows you to leverage what you need for a book outline.
Comment #17
osopolarThanks for the workaround, using fake publish/unpublished. I'll check this.
Comment #20
Andy_D CreditAttribution: Andy_D at Investis Digital commentedUpdating this as it's been far too long!
Comment #21
Andy_D CreditAttribution: Andy_D at Investis Digital commentedDoes not apply to 8. Also worth noting you check the book structure to ensure valid content is able to be added to books.
Comment #22
Andy_D CreditAttribution: Andy_D at Investis Digital commentedComment #23
jhedstromFor those coming into this issue from searching, the corresponding D8 issue is #26552: Allow users with access to unpublished nodes to create unpublished books.
Comment #24
joelpittetI couldn't seem to get the patch in #10 to work, the unpublished pages were still not visible in the admin. I am going to experiment with draggable views as it may get me a better UI in the long run.