When I’m trying to edit a page with inline entity form inside a paragraph in a “Closed” form state I get error:

TypeError: Argument 1 passed to Drupal\Core\Field\WidgetBase::massageFormValues() must be of the type array, null given, called in /var/www/drupalvm/docroot/modules/contrib/inline_entity_form/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php on line 577 in Drupal\Core\Field\WidgetBase->massageFormValues() (line 505 of core/lib/Drupal/Core/Field/WidgetBase.php).

Comments

dima.iluschenko created an issue. See original summary.

dima.iluschenko’s picture

Uploaded quick patch.

reekris’s picture

I have the the same issue, however your patch seems to have changes to code indentation. Here is a patch that just returns if $widget_state == null. This seems to fix the issue for me.

dima.iluschenko’s picture

right :), it's better for reading. small change for drupal standard ;)

reekris’s picture

Ah, thanks :)

reekris’s picture

Status: Active » Needs review
dawehner’s picture

@reekris
I'm wondering whether you understand exactly why this happens? If yes, it would be really helpful for @bojanz to know why, so reviewing the patch is much easier.
Hiding some error though is often not the best idea.

jlbellido’s picture

Subscribed, I agree that the current patch is not a solution and we need to know what the real problem is.

ndeet’s picture

dawehner’s picture

Issue tags: +Needs tests

Let's indicate with tests that we have actual problems. Yeah just guessing around has potentially more unforeseen consequences.

dawehner’s picture

Status: Needs review » Needs work
n8tron’s picture

I was getting the same error(s) while nesting multiple paragraphs with IEF. "Update Node/Create Node" button threw this error(s) and failed. When I click "Save and Keep Published" the errors are a follows.

Warning: Invalid argument supplied for foreach() in inline_entity_form/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php on line 558

Warning: uasort() expects parameter 1 to be array, null given in inline_entity_form/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php on line 578

Catchable fatal error: Argument 1 passed to Drupal\Core\Field\WidgetBase::massageFormValues() must be of the type array, null given, called in inline_entity_form/src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php on line 580 and defined in core/lib/Drupal/Core/Field/WidgetBase.php on line 505

This patch seems to have corrected the issue. I'm still looking into things...

melvinlouwerse’s picture

I have tried to figure this one out to see where it goes wrong

Fist of all this only happens with the paragraphs module when the form display is set to preview.
It also only happens when you are editing a node that has at least 1 paragraph with an (complex) inline entity form prior saved.

When you save your node (without changing anything) it will give this fatal error.

If you just open the paragraph to edit it and then close it again without saving anything you will be able to save.

The problem seems to be because the paragraph module in just preview mode does not render the inline entity form until the edit button is pushed.

Because the form is not rendered this following code src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php line 190 is not executed

    // Assign a unique identifier to each IEF widget.
    // Since $parents can get quite long, sha1() ensures that every id has
    // a consistent and relatively short length while maintaining uniqueness.
    $this->setIefId(sha1(implode('-', $parents)));

So when on save the paragraphs module asks in paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php extractFormValues (trough widgetbase /core/lib/Drupal/Core/Field/WidgetBase.php line 370 ) to run massageFormValues it will arrive on
src/Plugin/Field/FieldWidget/InlineEntityFormComplex.php on line 551

$ief_id = sha1(implode('-', $parents));

This will create a sha1 hash to find the inline form in our form state.

But since it was never created we receive NULL the rest of the code does not check or warn that the inline form was not found. We end up on line 576 with an empty $value variable causing the fatal error.

In this case the patch would work because an empty widget_state in this case is a valid state as we never had that inline form we did not change it so we dont need to do anything with its values.

Not sure if it would potentially break other stuff though.

I hope this helps

fathershawn’s picture

I have this issue, with IEF in complex mode, but Paragraphs is set to closed. I'm working to investigate further but posting here to save someone re-configuring their Paragraph form displays to try to work around.

melvinlouwerse’s picture

Closed has actually the same issue, No form is loaded initially, You need to click the edit button to load in the form.

The problem seems to be because the paragraph module in just preview mode does not render the inline entity form until the edit button is pushed.

So this is true for closed as well.

chr.fritsch’s picture

Apply the latest patch from #2804377: Saving problem in preview mode with IEF items to your paragraphs module, should fix the issue

geek-merlin’s picture

Status: Needs work » Closed (outdated)

Fixed as of #16.

geek-merlin’s picture

Status: Closed (outdated) » Needs work
Related issues: +#3118310: Bug with paragraph module

This was reported again it seems.

damien laguerre’s picture

I encountered this issue and it's due to the way to generate the ids.
It has changed:

Before:
$this->setIefId(sha1(implode('-', $parents)));
Now:
$this->setIefId(Crypt::hashBase64(implode('-', $parents)));

If you have extends/write a custom widget, make attention to use the new encoding.

geek-merlin’s picture

geek-merlin’s picture

Status: Needs work » Postponed (maintainer needs more info)

IEF rc9 is out and has some fixes for nested forms. Can this still be reproduced?

Drupalengue’s picture

Yes, this still happens. I got this error on RC9 on a complex paragraphs + IEF form:

TypeError: Argument 2 passed to Drupal\Component\Utility\NestedArray::getValue() must be of the type array, null given, called in /site.com/html/modules/contrib/paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php on line 1309 in Drupal\Component\Utility\NestedArray::getValue() (line 69 of /site.com/html/core/lib/Drupal/Component/Utility/NestedArray.php)

when adding more than 1 Entity with IEF inside a paragraph and then saving the form. If more details are needed I can try on a fresh install and try to write down the steps. This happens on a complex form with multiple paragraphs (some have 3 levels deep) and 1 Entity added to them using IEF. Form displays are set to simple and with Edit mode preview->open in most cases.

socialnicheguru’s picture

Status: Postponed (maintainer needs more info) » Needs work
thomwilhelm’s picture

StatusFileSize
new7.59 KB

Just ran into this when upgrading to 1.0-rc10 from 1.0-rc9.

TypeError: Argument 2 passed to Drupal\Component\Utility\NestedArray::getValue() must be of the type array, null given, called in /mnt/www/html/rfepaasjfmsen3/docroot/modules/contrib/paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php on line 1306 in Drupal\Component\Utility\NestedArray::getValue() (line 69 of /mnt/www/html/rfepaasjfmsen3/docroot/core/lib/Drupal/Component/Utility/NestedArray.php)

Attaching a full stack trace. Reverting to 1.0-rc9 fixed this issue!

berdir’s picture

Note: I didn't investigate yet, but our IEF integration test in the paragraphs module is failing with a PHP notice, which might be related to that (Notice: Undefined index: array_parents: https://www.drupal.org/pift-ci-job/2332366).

dahousecat’s picture

I also have this issue.
Can confirm reverting to 1.0-rc9 fixed the problem.