Problem/Motivation
While testing #1968982: Convert book theme tables to table #type, found a bug.
Steps to reproduce
- Install Drupal 8 using the Standard profile.
- Enable the Book module.
- Create a book page (/node/add/book), setting the value in Book outline > Book to '- Create a new book -'.
- Save the form at /admin/structure/book/1.
Current behavior:
Notice: Undefined index: table in Drupal\book\Form\BookAdminEditForm->submitForm() (line 100 of core/modules/book/src/Form/BookAdminEditForm.php).
Warning: array_keys() expects parameter 1 to be array, null given in Drupal\book\Form\BookAdminEditForm->submitForm() (line 100 of core/modules/book/src/Form/BookAdminEditForm.php).
Warning: array_flip() expects parameter 1 to be array, null given in Drupal\book\Form\BookAdminEditForm->submitForm() (line 100 of core/modules/book/src/Form/BookAdminEditForm.php).
Warning: array_merge(): Argument #1 is not an array in Drupal\book\Form\BookAdminEditForm->submitForm() (line 101 of core/modules/book/src/Form/BookAdminEditForm.php).
Recoverable fatal error: Argument 1 passed to Drupal\Core\Render\Element::children() must be of the type array, null given, called in /Users/sreeves/Sites/d8.dev/core/modules/book/src/Form/BookAdminEditForm.php on line 103 and defined in Drupal\Core\Render\Element::children() (line 75 of core/lib/Drupal/Core/Render/Element.php).
Proposed resolution
Seems like the keys expected by the submit handler are incorrect.
Remaining tasks
- Write patch
- Will need to write a webtest to prevent this from happening again.
User interface changes
n/a
API changes
TBD
Comments
Comment #1
star-szrUpdating STR and confirming the bug.
Comment #2
star-szrComment #3
andrei.dincu commentedCheck if $form_state['table'] is set in BookAdminEditForm and add test function testEmptyBook() in BookTest.
Comment #4
star-szrThanks @andrei.dincu! Can we get a test-only patch uploaded please so we can see that the test catches the bug? Similar to what you see on #2348413: Fatal error at /admin/structure/book.
This function needs a docblock (all functions do), and the indentation of the inline comment is too much. Please see https://www.drupal.org/node/1354#drupal and https://www.drupal.org/node/1354#inline for more info. :)
I would also suggest that the $book variable is not necessary, just use $this->book, but that's debatable.
Comment #6
star-szrWorking on some updates to the test, hope you don't mind @andrei.dincu!
Comment #7
star-szrA few updates to the test besides the docs, these are the important changes:
Comment #9
joelpittetAwesome, tagging for the sprint tomorrow:
Someone should run through this patch on simplytest.me with the issue summary steps and if all is good, RTBC!
Comment #10
tomefa commentedI will test this patch now.
Comment #11
tomefa commentedI applied the patch and followed the steps on simplytest.me
No error on the php_error log file or in the drupal log and nothing on the screen too.
Comment #12
alexpottCommitted 2e60dbb and pushed to 8.0.x. Thanks!