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;
            }

Issue fork drupal-3023924

Command icon 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

hassebasse created an issue. See original summary.

hassebasse’s picture

Issue summary: View changes
cilefen’s picture

Priority: Critical » Major
Issue tags: -Layout Builder

If this is not damaging stored data, then it is major priority.

hassebasse’s picture

OK for major priority, but I can't use the module and I found that quite critical

tim.plunkett’s picture

Version: 8.6.5 » 8.7.x-dev
Status: Active » Postponed (maintainer needs more info)
Issue tags: +Needs steps to reproduce

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

hassebasse’s picture

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

tim.plunkett’s picture

StatusFileSize
new612 bytes

This won't solve any problems but might help us debug it.

This should cause the offending values to print to the screen.

tim.plunkett’s picture

Component: layout_builder.module » forms system
Issue tags: +Needs tests
StatusFileSize
new862 bytes

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

cilefen’s picture

@hassebasse Side note: you have a patch workflow. That's relatively advanced!

tim.plunkett’s picture

+++ b/core/lib/Drupal/Component/Utility/NestedArray.php
@@ -152,6 +152,10 @@ public static function setValue(array &$array, array $parents, $value, $force =
+      if (isset($ref) && !is_array($ref)) {

This should have been elseif not if

hassebasse’s picture

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

hassebasse’s picture

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

hassebasse’s picture

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

tim.plunkett’s picture

Do you have the Display Suite module installed?

hassebasse’s picture

Yes, DS is installed.

tim.plunkett’s picture

Component: forms system » layout_builder.module
Priority: Major » Normal
Status: Postponed (maintainer needs more info) » Closed (duplicate)
Issue tags: -Needs steps to reproduce, -Needs tests

That answers #5 and is the problem. See #2966959: Value Conflict with Layout Builder for an existing issue in Display Suite to fix this.

hassebasse’s picture

Thank you for your help, and sorry for duplicating. It works fine when turning off DS.

aswathyajish’s picture

#8 worked for me. Thanks.

casaran’s picture

I have this same issue with the Layout Paragraph module https://www.drupal.org/project/layout_paragraphs and #8 fixed it for me

asherry’s picture

We'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:

[
  0 => "title",
  1 => 0,
  2 => "value"
]

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.

asherry’s picture

Nevermind 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

asherry’s picture

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

kazah’s picture

Version: 8.7.x-dev » 9.3.x-dev
Status: Closed (duplicate) » Needs review

Patch #8 works for D9.3.5 for layout builder.

Need to add to core

bserem’s picture

Status: Needs review » Reviewed & tested by the community

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

bserem’s picture

tim.plunkett’s picture

Version: 9.3.x-dev » 9.4.x-dev
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests, +Needs steps to reproduce

Needs work for tests, and for steps to reproduce the bug.

bserem’s picture

Tests are green against 9.4.x. Do they need something more than that?

cilefen’s picture

Yes. There needs to be a test added that fails without the bug fix. And we need steps to reproduce.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

catch’s picture

Component: layout_builder.module » forms system

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

john.nie’s picture

StatusFileSize
new878 bytes

it adopt with docroot is web.

arthur.baghdasar’s picture

StatusFileSize
new862 bytes

Rerolled the patch

aswathyajish’s picture

I have the same issue in drupal 9.4.5 version. I tried #31 and it worked. Thanks for the patch.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

er_abhinav’s picture

Hi ,

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

kunalgautam’s picture

Status: Needs work » Needs review
StatusFileSize
new856 bytes

Rerolled the patch version 10.1.x

bserem’s picture

Status: Needs review » Needs work

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

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

pcfoster’s picture

Issue summary: View changes
pcfoster’s picture

nlisgo made their first commit to this issue’s fork.

guillaumeg’s picture

Hi,

This patch was helpful in resolving an issue described at https://www.drupal.org/project/better_exposed_filters/issues/3299926#com...

phthlaap made their first commit to this issue’s fork.

phthlaap’s picture

Title: Cannot create references to/from string offsets » An error occurs in Views when attempting to add an exposed filter by ID with the 'Allow multiple selections' option enabled.
phthlaap’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: -Needs tests +Needs issue summary update

Issue summary should be updated to use the standard issue template.

pradhumanjain2311 made their first commit to this issue’s fork.

phthlaap’s picture

Issue summary: View changes
phthlaap’s picture

Issue summary: View changes
StatusFileSize
new642.82 KB
phthlaap’s picture

Status: Needs work » Needs review
smustgrave’s picture

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

smustgrave’s picture

Status: Needs review » Needs work

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

smustgrave’s picture

Just got bit by this on better_exposed_filters

baluertl’s picture

Title: An error occurs in Views when attempting to add an exposed filter by ID with the 'Allow multiple selections' option enabled. » An error occurs in Views when attempting to add an exposed filter by ID with the 'Allow multiple selections' option enabled
niranjan_panem’s picture

Checked 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.
sreenshot-of-array-in query parameter

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.