Scenario:

  1. A paragraph bundle contains an entity reference field (node).
  2. A paragraphs field using the bundle is configured to use the "preview " edit mode.
  3. A referenced node has been deleted without first removing the reference.
  4. Trying to edit or remove the pargraphs item that contains the missing reference causes a fatal error.

Background on the error:

  1. InlineParagraphsWidget::elementValidate() calls $display->validateFormValues().
  2. A ValidReferenceConstraint violation is detected.
  3. Ultimately WidgetBase::flagErrors() is called which attempts to retrieve the widget state.
  4. $field_state is null, and thus null gets passed as second argument to NestedArray::getValue() which causes:
    Recoverable fatal error: Argument 2 passed to Drupal\Component\Utility\NestedArray::getValue() must be of the type array, null given
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ciss created an issue. See original summary.

ciss’s picture

I just did another check with the "closed" edit mode, achieving the same result. Only the "open" edit mode allows the item to be edited or removed.

ciss’s picture

Title: Edit mode "preview" chokes on invalid entity references » Edit modes "closed" and "preview" choke on invalid entity references

Updating issue title.

johnchque’s picture

What field type where you using to make the reference to the node? in:

A referenced node has been deleted without first removing the reference.

ciss’s picture

The field type is a Drupal 8.0.6 core entity reference field. The field config can be found here: https://goo.gl/80IuXY

johnchque’s picture

This should fix the problem but not sure if this is the correct aproach.

miro_dietiker’s picture

If remove and removed was excluded, what ist the item state then of the item that accidentally triggers validation?

miro_dietiker’s picture

Issue tags: +Needs tests

Ah i see... And since editing can only happen in edit state, your approach makes sense.

Test coverage? ;-)

The last submitted patch, 9: edit_modes_closed_and-2708033-9-test-only.patch, failed testing.

The last submitted patch, 9: edit_modes_closed_and-2708033-9-test-only.patch, failed testing.

The last submitted patch, 9: edit_modes_closed_and-2708033-9-test-only.patch, failed testing.

chr.fritsch’s picture

johnchque’s picture

@chr.fritsch I think would be better to have a separated issue to fix the problem you refer. Also if would be much better to have test coverage for what you describe and provide a test-only patch that should fail.

johnchque’s picture

Status: Needs review » Needs work

Tested a bit more, we need extra tests.

johnchque’s picture

We definitely need to refactor tests after release. Added tests, Discussed with @Berdir we shouldn't be able to collapse with an invalid reference.

johnchque’s picture

Status: Needs review » Needs work

The last submitted patch, 17: edit_modes_closed_and-2708033-16-test-only.patch, failed testing.

The last submitted patch, 17: edit_modes_closed_and-2708033-16-test-only.patch, failed testing.

The last submitted patch, 17: edit_modes_closed_and-2708033-16-test-only.patch, failed testing.

johnchque’s picture

Status: Needs work » Needs review

Glad to know test only patch failed. :)

Berdir’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Nice, looks good to me.

As a follow-up, Miro and I discussed that we could do the following:

For closed paragraphs, directly validate them with $entity->validate(). If there are validation errors, just list them within the closed paragraph as error messages. On submit, fail validation on them, just add the messages on the current form element.

Can you create that?

miro_dietiker’s picture

Status: Reviewed & tested by the community » Needs work

Committed.

Back to needs work to create the followups. Please close when created and referenced.

johnchque’s picture

Status: Needs work » Fixed
Related issues: +#2733987: Validate closed Paragraphs

Issue created.

Status: Fixed » Closed (fixed)

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