"This value should not be null." on node preview

Created on 21 December 2017, almost 7 years ago
Updated 11 September 2023, over 1 year ago

Problem/Motivation

An entity reference field with the Complex widget is returning a vague error ("This value should not be null.") without indicating what field or value is incorrect. Sometimes nothing is incorrect, and it's the fact that inline_entity_form isn't adding values to the main entity before it's validated.

In some cases this is happening when all the fields are filled in, such as on clicking the "preview" button when adding a new node.

Steps to reproduce:

1) go to https://simplytest.me/ and select "Inline Entity Form" as the project

2) Once site launches, add an entity reference field on the article content type to reference the page content type

3) Edit the form display to use the Complex Widget widget.

4) Create a test page node (/node/add/page)

5) Go to create an article node (/node/add/article), fill in all the fields (including the reference to the page node you created

6) Click Preview

7) Observe error.

Expected: You should see a preview of your node with the image displaying

Actual: An error message "This value should not be null." and the form reloads. I traced it back to validation on the image field (see stack trace below).

Proposed resolution

I'm not sure of the best approach yet. I have a patch, but it needs review.

Next Steps

- test coverage to demonstrate the error
- needs review
- needs test coverage for the fix

✨ Feature request
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States oknate Greater New York City Area

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡¦Ukraine quadrexdev Lutsk

    Attaching a new patch with a changed check in inline_entity_form_node_preview_builder.

    Comparing the "op" title didn't work for me cuz there could be a project-specific case with a changed title of the button. That will lead to a failed check

    if (\Drupal::request()->request->get('op') == t('Preview'))
    

    So, added a check by triggered element ID. Not sure this is the best way but it works for any button title (Preview/Live preview/etc).

Production build 0.71.5 2024