Problem/Motivation
Generically, the issue seems to be no graceful failure when form builder expects an array and gets a string.
Steps to Reproduce: method 1
- Create a page view for Content with url: /test-filter-grouped-id
- Add a Content ID filter
- Select Expose this filter to visitors, to allow them to change it
- Select Grouped filters, see my screenshot
- Select Allow multiple selections
- In the group table, add Group 1 is equal to 1
- In the group table, add Group 2 is equal to 2
- In the group table, add Group 3 is equal to 3
- Save view
- Goto page /test-filter-grouped-id?nid=1 the issue will happen
Steps to Reproduce: method 2
- Create a view.
- Add a filter (e.g. a taxonomy with filter identifier "tid"), make it exposed; configure the filter to "Allow multiple selections"
- Make a page display (e.g. "/test_view") to allow easy access to the filter query params. Save and navigate to the page.
- Use the exposed filter and note that the URL becomes something like "test_view?tid[N]=N" where N is the id of your taxonomy term.
- Change the query parameter to be something like "?tid=foo".
Note that you get a fatal error "Cannot create references to/from string offsets in /mnt/www/html/[project]/docroot/core/lib/Drupal/Component/Utility/NestedArray.php on line 155 #0
/mnt/www/html/[project]/docroot/core/lib/Drupal/Core/Form/FormBuilder.php(1259): Drupal\Component\Utility\NestedArray::setValue(Array, Array, NULL) #1"
This error is identical to that mentioned in original issue description, summarized here:
When Layout builder is active and I try to save a Content type "The website encountered an unexpected error. Please try again later." turns up and I have the below errors. What could this be?
PHP 7.2.13-1+0~20181207100540.13+stretch~1.gbpf57305
DB 5.5.5-10.1.37-MariaDB-0+deb9u1
Error: Cannot create references to/from string offsets i Drupal\Component\Utility\NestedArray::setValue() (rad 155 av /web/core/lib/Drupal/Component/Utility/NestedArray.php)... [rest of stack trace omitted]
Note that the patches offered below (with the exception of the debug patch) are essentially identical and differ only in the line number in core/lib/Drupal/Core/Form/FormBuilder.php where the change is applied.
The patch has worked for me (D9.5.9, PHP8.1) with custom views - again, with a different line number.
Proposed resolution
Modify core/lib/Drupal/Core/Form/FormBuilder.php:1242
Before:
NestedArray::setValue($form_state->getUserInput(), $element['#parents'], NULL);
After:
NestedArray::setValue($form_state->getUserInput(), $element['#parents'], NULL, TRUE);
Modify core/modules/views/src/Plugin/views/filter/NumericFilter.php:448
Before:
case 1:
if ($value['value'] === '') {
return FALSE;
}After:
case 1:
if (isset($value['value']) && $value['value'] === '') {
return FALSE;
}
| Comment | File | Size | Author |
|---|---|---|---|
| #57 | Screenshot-of-array-as-parameter-in-drupal-11.png | 84.27 KB | niranjan_panem |
Issue fork drupal-3023924
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
hassebasse commentedComment #3
cilefen commentedIf this is not damaging stored data, then it is major priority.
Comment #4
hassebasse commentedOK for major priority, but I can't use the module and I found that quite critical
Comment #5
tim.plunkettDo you have any custom code that might affect this? Or any other contrib modules that would affect the content type form or manage display form?
Also, the call on FormBuilder line 1245 is the broken one according to that backtrace.
The two arguments are
$form_state->getUserInput()and$element['#parents'].Can you find what those two values are?
Comment #6
hassebasse commentedI'm not very advanced in this, but I'll give it a try:
I have no custom modules but I have applied patches according to below
"drupal/page_manager": {
"Drupal Page Manager Clicking a variant in page manager does not open the variant config in 8.x-4.0-beta3 ": "https://www.drupal.org/files/issues/page_manager-2874851-8.patch"
},
"drupal/panels": {
"Drupal Panels Not saving change in 8.x-4.3": "https://www.drupal.org/files/issues/update_layout_fix.patch"
},
"drupal/workbench_moderation": {
"Problems with PHP7.2": "https://www.drupal.org/files/issues/2018-04-16/workbench_moderation_inco..."
}
(Concerning workbench_moderation, I'm not using the module, it is inactive.)
When it comes to your second question I don't understand what you are talking about :-) Pls tell me what to look for.
Comment #7
tim.plunkettThis won't solve any problems but might help us debug it.
This should cause the offending values to print to the screen.
Comment #8
tim.plunkettAlso I haven't really thought about the implications of this change, but it might work, and be technically more correct?
Still needs the steps to reproduce so we can write tests.
Comment #9
cilefen commented@hassebasse Side note: you have a patch workflow. That's relatively advanced!
Comment #10
tim.plunkettThis should have been
elseifnot ifComment #11
hassebasse commentedcilefen: I am not very advanced. What is a Patch Workflow? I do install the pathces using composer and making changes in composer.json
tim.plunkett: Number 10 I don't understand at all. Pls explain. I will now install the patches in 7 and 8. I'll let you know what happends
Comment #12
hassebasse commentedAfter applying the debug-patch (corrected version) I had this on the screen
string(5) "_none" string(7) "enabled" The website encountered an unexpected error. Please try again later.Comment #13
hassebasse commentedOK, Now I have applied the patch in #8 and this time there is no white screen with a message when trying to save, but instead I have a read square with a text saying "Illeagal choise, choose a layout element".
I already have Boxton from Radix but but if I try to change that to something else, the same message turns up, so it is still impossible to save.
Comment #14
tim.plunkettDo you have the Display Suite module installed?
Comment #15
hassebasse commentedYes, DS is installed.
Comment #16
tim.plunkettThat answers #5 and is the problem. See #2966959: Value Conflict with Layout Builder for an existing issue in Display Suite to fix this.
Comment #17
hassebasse commentedThank you for your help, and sorry for duplicating. It works fine when turning off DS.
Comment #18
aswathyajish commented#8 worked for me. Thanks.
Comment #19
casaran commentedI have this same issue with the Layout Paragraph module https://www.drupal.org/project/layout_paragraphs and #8 fixed it for me
Comment #20
asherry commentedWe're also having the same issue here with layout_paragraphs and Drupal core 9.1.6. For what it's worth the parents of the error causing element are:
The base node is a node type called "landing_page" that we have, and it's using a paragraphs field called "field_content". I can create it fine, but then when I go to edit anything it throws an ajax error. We're not using display suite.
Comment #21
asherry commentedNevermind my last post, I think it had something to do with a module that we have installed called "permissions_by_term". If anybody else has that same module enabled, there is an issue for it already https://www.drupal.org/project/permissions_by_term/issues/3072607
Comment #22
asherry commentedSorry, did some more testing, it turns out it's still an issue even with the patches from permissions_by_term. It'd be great to dig into this a bit further and see if it's maybe a separate issue.
Comment #23
kazah commentedPatch #8 works for D9.3.5 for layout builder.
Need to add to core
Comment #24
bserem commentedPatch #8 solves the problem when using layout_paragraphs and referencing an entity with a form (ex: reference a view with an exposed form).
I queued some tests, if they pass then maybe we RTBC this?
Comment #25
bserem commentedComment #26
tim.plunkettNeeds work for tests, and for steps to reproduce the bug.
Comment #27
bserem commentedTests are green against 9.4.x. Do they need something more than that?
Comment #28
cilefen commentedYes. There needs to be a test added that fails without the bug fix. And we need steps to reproduce.
Comment #30
catchJust came across this, no simple steps to reproduce yet.
The situation was a view with exposed filters/sorts with some changes after a deployment. A stale link to the view with filters applied resulted in this error. After the patch, instead you end up with "An illegal choice has been detected. Please contact the site administrator." Unfortunately not a view you can build with stock Drupal core, but if I get time later I'll see if I can trim things down to some steps to reproduce.
Moving to form API since there appears to be multiple ways to trigger this.
Comment #31
john.nie commentedit adopt with docroot is web.
Comment #32
arthur.baghdasar commentedRerolled the patch
Comment #33
aswathyajish commentedI have the same issue in drupal 9.4.5 version. I tried #31 and it worked. Thanks for the patch.
Comment #35
er_abhinav commentedHi ,
I am using Drupal version 9.4.9 and PHP 8.1
#32 worked perfectly for me.
https://www.drupal.org/project/drupal/issues/3023924#comment-14689664
Comment #36
kunalgautam commentedRerolled the patch version 10.1.x
Comment #37
bserem commented@kkalashnikov thanks for the updated patch. As per the instructions in comment 28 above, this needs more tests before it can be submitted.
Setting back to needs work.
Comment #39
pcfoster commentedComment #40
pcfoster commentedComment #42
guillaumeg commentedHi,
This patch was helpful in resolving an issue described at https://www.drupal.org/project/better_exposed_filters/issues/3299926#com...
Comment #45
phthlaap commentedComment #46
phthlaap commentedComment #47
phthlaap commentedComment #48
smustgrave commentedIssue summary should be updated to use the standard issue template.
Comment #50
phthlaap commentedComment #51
phthlaap commentedComment #52
phthlaap commentedComment #53
smustgrave commentedHiding patches for clarity. Leaving issue summary tag as proposed solution is mentioning the code changes and not really why the solution. Will leave in review for others to take a look.
Comment #54
smustgrave commentedBeen over a week so going to move to NW for the proposed solution. I see the code change in the MR but why is that needed. Also left a comment on the MR.
Comment #55
smustgrave commentedJust got bit by this on better_exposed_filters
Comment #56
baluertlComment #57
niranjan_panem commentedChecked the steps to reproduce in drupal 11, actually if we selected multiple select options in expose filter settings in views setting page. Drupal automatically sets the query parameter to array parameters like

test-filter-grouped-id?nid%5B2%5D=2. Below is the screen shot of it.