I received the following PHP error when trying to create or view a content type that contained some Entity Browser fields:
PHP Fatal error: Call to a member function getDisplay() on null in /modules/entity_browser/src/Element/EntityBrowserElement.php on line 163
The issue was related to two Image fields that were using the Entity Browser. They were created when we had a previous version of Entity Browser installed (earlier 8.x branch). When I went to add a new field to the content type, the admin worked fine, but the content type display crashed with a 500 error.
The problem was with the Form Display. Entity Browser was selected as the field type for those two image fields, but there was a null browser in the settings. My guess is that this was due to architectural changes between releases. It only became an issue when I updated the content type.
I went into the settings for those two fields, selected the "Browser for Files" EB, saved the changes and now everything is working fine.
My suggestion would be to hook into the Display Form update and check for a null Entity Browser field condition. If that exists, prompt the admin of the issue so that they can correct.
Comment | File | Size | Author |
---|---|---|---|
#29 | interdiff.txt | 968 bytes | slashrsm |
#29 | 2820132_29.patch | 3.32 KB | slashrsm |
#25 | 2820132.patch | 4.27 KB | geekinpink |
#19 | 2820132-19.patch | 3.2 KB | ZeiP |
#17 | entity_browser-8.x-1.0-2820132-17.patch | 1.93 KB | Rajab Natshah |
Comments
Comment #2
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedThat would definitely improve usability and prevent confusion. Let's do this.
Comment #3
marcoscanoNot sure if form_alter is the only way of adding our validation logic to entity form displays... but couldn't find another way of doing it. Will appreciate feedback.
Comment #4
matthieuscarset CreditAttribution: matthieuscarset as a volunteer and commentedHi and thank you for creating this issue.
I had the same issue with a custom entity containing an Entity Browser which has been deleted.
I propose to simply try to NOT getDisplay() but to replace the $element['entity_browser'] by an error message.
Comment #5
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedI like the approach in #4. I think that we should also show the name of the missing EB in the error message.
Patch violates few coding standard rules. Would be great to run it through CodeSniffer.
Comment #6
matthieuscarset CreditAttribution: matthieuscarset as a volunteer and commentedThank you for your review @slashrsm
I've run CodeSniffer on my code and I've regenerated a patch.
Hopefully it is compliant with coding standard rules now.
Comment #7
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedComment #8
Joachim NamysloCouldyou apply this plz. got the error and it drives me crazy
Comment #9
GiorgosKI did not have any media on the a image field and configured it to use entity_browser
but then no node would be able to be edited (500 error on node/xx/edit)
patch in # applied cleanly
and now I can edit the nodes again
EDIT: Turns out I did not have "entity browser" selected but still should not give me such error
Comment #10
hamrant CreditAttribution: hamrant at DEWEB Studio for Drupal Ukraine Community commentedGo to 'Manage form display' of your content type and re-save image widget settings, it helps me with the same error
Comment #11
Rajab Natshah CreditAttribution: Rajab Natshah at Vardot commentedThank you :)
Comment #13
Enaj CreditAttribution: Enaj commentedThe problem is still relevant. Patches do not solve it.
After applying the patch, when creating the material, I see the inscription - "Entity browser not found".
Comment #14
hamrant CreditAttribution: hamrant at DEWEB Studio for Drupal Ukraine Community commented@Enaj check my comment #10, maybe this will help
Comment #15
Enaj CreditAttribution: Enaj commented@hamrant I tried, it did not help.
Comment #16
Enaj CreditAttribution: Enaj commented@hamrant You were right, your advice helped. The first time I changed the display settings and not the field settings.
Comment #17
Rajab Natshah CreditAttribution: Rajab Natshah at Vardot commentedUpdated the patch for entity browser 8.x-1.0
Comment #18
hamrant CreditAttribution: hamrant at DEWEB Studio for Drupal Ukraine Community commentedComment #19
ZeiP CreditAttribution: ZeiP at Citrus Solutions Oy commentedThe patch in #17 didn't work, since some of the rows were left outside the if(). Attached is a fixed patch, which is a re-roll of the patch in #6.
Comment #20
ZeiP CreditAttribution: ZeiP at Citrus Solutions Oy commentedComment #21
makbeta CreditAttribution: makbeta as a volunteer commented#19 worked like a charm for me. Thank you @ZeiP
Comment #22
Anybody#19 works great. Can we have a new release soon please, which contains this fix? That would be very very helpful.
Comment #23
samuel.mortensonI think the element should still return _something_, even if the Entity Browser doesn't exist. There should be a message of some kind that informs them that the form configuration is invalid, or that the Entity Browser doesn't exist. Seeing nothing doesn't inform users that there's a problem.
Comment #24
samuel.mortensonComment #25
geekinpink CreditAttribution: geekinpink as a volunteer and commentedGiven patch was not applying on version entity_browser 8.x-1.1.
Added updated patch for this version.
Comment #26
carolpettirossi CreditAttribution: carolpettirossi at Digital Garden commented#19 worked fine here as well. Any plans to a new release?
Thanks
Comment #27
samuel.mortensonI think my review from #23 missed the markup text that informs users that the Entity Browser doesn't exist, sorry about that! Once a new patch is re-rolled we can put the issue back in RTBC.
Comment #28
ZeiP CreditAttribution: ZeiP at Citrus Solutions Oy commentedThe patch applies just fine against 8.x-1.x HEAD, it was the 8.x-1.1 release that required a changed patch. As the patch applies, I'm changing the issue to RTBC per @samuel.mortenson's suggestion. Thanks!
Comment #29
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedFew minor fixes.
Comment #30
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedCommitted. Thanks!
Comment #32
Liakoni CreditAttribution: Liakoni commentedAfter i applied the patch #29 i got another error:
I tried in a field in form display and i got this error. In the editor it works fine.
Comment #33
Tsymi CreditAttribution: Tsymi at Axess Open Web Services commentedHi,
Error found on #32 has been fixed in this issue : https://www.drupal.org/node/2909945#comment-12264581