Problem/Motivation

Saving Book configuration is not possible due to an error in form validation. See attached image.

Steps to reproduce

  1. Install the latest Drupal 8.9.x using the standard profile.
  2. enable the Book module
  3. Go to admin/structure/book/settings and save the configuration form. You will get an error.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Original report by [JD_1]

The created patch is breaking my configuration.
See attached image after which occurs after patching to D8.9.7(+)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JD_1 created an issue. See original summary.

dbielke1986’s picture

I need to revert the changes which were made here:

https://git.drupalcode.org/project/drupal/commit/cb2e043f53fcf05dd20d164...

dbielke1986’s picture

Title: Clean-up remains of $form['array_filter'] hack with array_filter in book module » Clean-up remains of $form['array_filter'] hack with array_filter in book module breaks my configuration
dbielke1986’s picture

Error which occurs:

"The content type for the Add child page link must be one of those selected as an allowed book outline type."

dbielke1986’s picture

I did some more research...

$child_types is empty after the following line:

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    $child_type = array_filter($form_state->getValue('book_child_type'));

array_filter() is not working, because "$form_state->getValue('book_child_type')" is just a string of the content type like "book"

dbielke1986’s picture

And I think it was mentioned here:

https://www.drupal.org/project/drupal/issues/315176#comment-12171773

The code is http://cgit.drupalcode.org/drupal/tree/core/modules/book/src/Form/BookSe...

allowed_types - checkboxes are filtered already
child_type is radios so no filtering required

So #27 is right patch that removes useless remains

So it only should be this patch be applied:
https://www.drupal.org/files/issues/315176-array_filter_remains-27.patch

dbielke1986’s picture

Title: Clean-up remains of $form['array_filter'] hack with array_filter in book module breaks my configuration » Drupal 8.9.7 breaks Book Settings Form Validation
Component: forms system » book.module
larowlan’s picture

Priority: Critical » Normal
Status: Active » Postponed (maintainer needs more info)
Issue tags: -DrupalWTF

Hi, can you please elaborate on what the issue is, e.g do you get an error, if so what is the error

Thanks

dbielke1986’s picture

Hi larowlan,

At the moment (with Drupal 8.9.7 and later) no one can activate a content type to create books or change the book settings.

The reason is the mentioned error in the form of the bool settings. Please see the attached screenshot.

It seems to me that the array_filter() function is killing the provided string, because it is just a string, not an array.

In the linked issue the comment (https://www.drupal.org/project/drupal/issues/315176#comment-12171773) reverts the patches which was committed to the core.

BR
Daniel

dbielke1986’s picture

Status: Postponed (maintainer needs more info) » Active
pefferen’s picture

Issue summary: View changes
pefferen’s picture

Rewrote the form validation and form submit methods, locally this works, I can save the form again, without getting a warning.

pefferen’s picture

Status: Active » Needs review
dbielke1986’s picture

Status: Needs review » Reviewed & tested by the community

@pefferen

Perfect! Exactly what I did to fix this problem.

Is working for me, too.

longwave’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

We need a test for this form to make sure we don't break it again.

longwave’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
751 bytes
2.01 KB

The last submitted patch, 16: 3181173-16-test-only.patch, failed testing. View results

larowlan’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Quickfix

  • catch committed 2311657 on 9.2.x
    Issue #3181173 by longwave, pefferen, JD_1, larowlan: Drupal 8.9.7...

  • catch committed 2796784 on 9.1.x
    Issue #3181173 by longwave, pefferen, JD_1, larowlan: Drupal 8.9.7...
catch’s picture

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 48d2c0c on 9.0.x
    Issue #3181173 by longwave, pefferen, JD_1, larowlan: Drupal 8.9.7...

  • catch committed 8010263 on 8.9.x
    Issue #3181173 by longwave, pefferen, JD_1, larowlan: Drupal 8.9.7...

Status: Fixed » Closed (fixed)

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