Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tamasd created an issue. See original summary.

cilefen’s picture

Priority: Normal » Major
Issue tags: -book

I feel like this may be a duplicate but I don't have time to search at the moment.

margyly’s picture

I don't see a duplicate. This is still a bug. If the page is already in a book you don't get an error. But if it's not in a book, you can't use "Create a new book" to make one.

cilefen’s picture

Title: Book outline: An illegal choice has been detected. Please contact the site administrator. » "Illegal choice 0 in Book element" when switching the book outline field from anything to "- None - "
Version: 8.2.x-dev » 8.7.x-dev
Issue summary: View changes
Issue tags: +Ajax

The bug is centered in \Drupal\book\BookManager::addFormElements. When Ajax reevaluates the form element, the "0" value is not added to the options.

    if (!$node->book['bid']) {
      // The node is not currently in the hierarchy.
      $options = [0 => $this->t('- None -')] + $options;
    }

    // Add a drop-down to select the destination book.
    $form['book']['bid'] = [
      '#type' => 'select',
      '#title' => $this->t('Book'),
      '#default_value' => $node->book['bid'],
      '#options' => $options,
      '#access' => (bool) $options,
      '#description' => $this->t('Your page will be a part of the selected book.'),
      '#weight' => -5,
      '#attributes' => ['class' => ['book-title-select']],
      '#ajax' => [
        'callback' => 'book_form_update',
        'wrapper' => 'edit-book-plid-wrapper',
        'effect' => 'fade',
        'speed' => 'fast',
      ],
    ];

(edited - fixed typos)

vomiand’s picture

This is happening becuase $form['book']['bid']['options'] changes depending on the choice.

vomiand’s picture

Status: Active » Needs review
cilefen’s picture

Status: Needs review » Needs work

Thank you @vomiand!

The identical operator could be used here:

$nid == 'new'

We should be able to add a front-end test for this.

vomiand’s picture

Updated comparison operator.

vomiand’s picture

Status: Needs work » Needs review
Vj’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

@vomiand #8patch works without issue and warning removed.

Lets add some tests for this.

The last submitted patch, 11: 2851504-11-illegal_choice-fail.patch, failed testing. View results

pawandubey’s picture

Patch#8 working fine and also the test cases are good and succeed.

Let's wait for others to review and we can move this to RTBC.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.9 was released on November 6 and is the final full bugfix release for the Drupal 8.7.x series. Drupal 8.7.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.8.0 on December 4, 2019. (Drupal 8.8.0-beta1 is available for testing.)

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

rpayanm’s picture

Status: Needs review » Reviewed & tested by the community

I applied the patch and worked as expected, I think we can move this to RTBC.

The last submitted patch, 11: 2851504-11-illegal_choice-fail.patch, failed testing. View results

The last submitted patch, 11: 2851504-11-illegal_choice-fail.patch, failed testing. View results

xjm’s picture

Fixing the file list so that the latest patch is shown, and updating issue credits. Thanks for working on this issue!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/book/tests/src/FunctionalJavascript/BookJavascriptTest.php
@@ -157,4 +157,23 @@ protected function assertOrderInPage(array $items) {
+    $book_select->setValue('new');
+    $session->wait(10000);
+    $book_select->setValue(0);
+    $session->wait(10000);

Rather than waiting for time to pass here we should be asserting something.

After selecting 'new' we should wait for the text This will be the top-level page in this book. and then test that No book selected. is not there.

And after selecting '0' we should wait for the text No book selected. and test that This will be the top-level page in this book. is no longer there.

alexpott’s picture

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

Given this is over a year old I made the changes recommended by #19 myself.

The last submitted patch, 20: 2851504-20.test-only.patch, failed testing. View results

alexpott’s picture

FileSize
1.49 KB

Forgot to upload an interdiff.

BalajiDS’s picture

Patch #20 is working fine in Drupal - 8.8.6, thanks @alexpott.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

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

mindbet’s picture

Version: 8.9.x-dev » 9.2.x-dev
Status: Needs review » Reviewed & tested by the community

Patch applied successfully to 9.2.0-dev

Tests passing. RTBC

  • catch committed 4397d8d on 9.2.x
    Issue #2851504 by alexpott, vomiand, Vj, BalajiDS, cilefen, tamasd: "...

  • catch committed 104f6cd on 9.1.x
    Issue #2851504 by alexpott, vomiand, Vj, BalajiDS, cilefen, tamasd: "...

  • catch committed 03d2620 on 9.0.x
    Issue #2851504 by alexpott, vomiand, Vj, BalajiDS, cilefen, tamasd: "...
catch’s picture

Version: 9.2.x-dev » 8.9.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 9.2.x and cherry-picked back through to 8.9.x, thanks!

  • catch committed 89a7184 on 8.9.x
    Issue #2851504 by alexpott, vomiand, Vj, BalajiDS, cilefen, tamasd: "...

Status: Fixed » Closed (fixed)

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