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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

wjaspers’s picture

Title: Can't save parent item of book correctly, always save the top-level » Book Outline settings fail when some content is unpublished
Version: 7.0-alpha3 » 7.x-dev
Issue tags: -drupal 7, -book module

Its 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.

Michael-IDA’s picture

Should 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"

Michael-IDA’s picture

Title: Book Outline settings fail when some content is unpublished » book.module should correctly handle unpublished content

going bigger picture, as you should be able to "construct a book without end-users seeing it or any of its contents."

soulston’s picture

This 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:

$query->addField('n', 'status', 'status');
$query->condition('n.status', array(0,1), 'IN');

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:

$ ack book_get_book

book.admin.inc
17:  foreach (book_get_books() as $book) {

book.module
273:    foreach (book_get_books() as $book_id => $book) {
367:function book_get_books() {
570:    foreach (book_get_books() as $book) {
674:      drupal_static_reset('book_get_books');
683:        drupal_static_reset('book_get_books');
989:    drupal_static_reset('book_get_books');

book.pages.inc
13:  foreach (book_get_books() as $book) {

book_unpublished_patch.patch
8:   foreach (book_get_books() as $book) {
23:@@ -377,10 +377,16 @@ function book_get_books() {
41:@@ -389,7 +395,10 @@ function book_get_books() {
66:     foreach (book_get_books() as $book) {

The other changes are mainly for the admin screens to output some helper text to tell you that a book is indeed unpublished.

wjaspers’s picture

Status: Active » Needs work
+++ b/modules/book/book.admin.incundefined
@@ -15,7 +15,12 @@ function book_admin_overview() {
+    if (isset($book['status']) && $book['status'] == 0) {

I'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".

+++ b/modules/book/book.moduleundefined
@@ -377,10 +377,16 @@ function book_get_books() {
+      ¶

Added tab character. Remove.

+++ b/modules/book/book.moduleundefined
@@ -377,10 +377,16 @@ function book_get_books() {
+      ¶

Added tab character. Remove.

+++ b/modules/book/book.moduleundefined
@@ -389,7 +395,10 @@ function book_get_books() {
+        // kpr($link);
       }
+      // kpr($result2);

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?

soulston’s picture

Thanks 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.

marcingy’s picture

Version: 7.x-dev » 8.x-dev

This needs to be fixed in d8 first and then backported.

das-peter’s picture

Issue summary: View changes
FileSize
4.04 KB

Updated patch for D7...

das-peter’s picture

Some 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().

Andy_D’s picture

Patch #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:

function theme_book_title_link($variables) {
  
  $link = $variables['link'];
  
  $link['options']['attributes']['class'] = array('book-title');

+  // check the title - if blank don't form a link
+  if (isset($link['title'])) { 
    return l($link['title'], $link['href'], $link['options']);
+ }
}
matason’s picture

In 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...

dtamajon’s picture

The 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:

  if ($include_unpublished) {
    return empty($all_books) ? array() : $all_books['all'];
  }
  return empty($all_books) || empty($all_books['published']) ? array() : $all_books['published'];

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.

moulie415’s picture

Rookie here needing help!!! This patch removes the table of contents for my books can anyone help me fix this?

osopolar’s picture

I 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?

ladybug_3777’s picture

osopolar, 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.

osopolar’s picture

Thanks for the workaround, using fake publish/unpublished. I'll check this.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Andy_D’s picture

Assigned: Unassigned » Andy_D
Issue tags: +mssprintjan17

Updating this as it's been far too long!

Andy_D’s picture

Version: 8.2.x-dev » 7.x-dev

Does not apply to 8. Also worth noting you check the book structure to ensure valid content is able to be added to books.

Andy_D’s picture

Assigned: Andy_D » Unassigned
Issue tags: -mssprintjan17
jhedstrom’s picture

For those coming into this issue from searching, the corresponding D8 issue is #26552: Allow users with access to unpublished nodes to create unpublished books.

joelpittet’s picture

I 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.