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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

keats76 created an issue. See original summary.

slashrsm’s picture

Version: 8.x-1.0-alpha9 » 8.x-1.x-dev
Category: Bug report » Task
Issue tags: +D8Media, +Usability

That would definitely improve usability and prevent confusion. Let's do this.

marcoscano’s picture

Status: Active » Needs review
FileSize
3.6 KB

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

matthieuscarset’s picture

FileSize
3.41 KB

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

slashrsm’s picture

Status: Needs review » Needs work

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

matthieuscarset’s picture

FileSize
3.09 KB

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

slashrsm’s picture

Status: Needs work » Needs review
Joachim Namyslo’s picture

Couldyou apply this plz. got the error and it drives me crazy

GiorgosK’s picture

I 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

cd modules/entity_browser
wget https://www.drupal.org/files/issues/ElementPatch_0.patch
git apply -v ElementPatch_0.patch

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

hamrant’s picture

Go to 'Manage form display' of your content type and re-save image widget settings, it helps me with the same error

Rajab Natshah’s picture

Thank you :)

Status: Needs review » Needs work

The last submitted patch, 6: ElementPatch.patch, failed testing.

Enaj’s picture

The 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".

hamrant’s picture

@Enaj check my comment #10, maybe this will help

Enaj’s picture

@hamrant I tried, it did not help.

Enaj’s picture

@hamrant You were right, your advice helped. The first time I changed the display settings and not the field settings.

Rajab Natshah’s picture

Updated the patch for entity browser 8.x-1.0

hamrant’s picture

Status: Needs work » Needs review
ZeiP’s picture

Category: Task » Bug report
FileSize
3.2 KB

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

ZeiP’s picture

Category: Bug report » Task
makbeta’s picture

#19 worked like a charm for me. Thank you @ZeiP

Anybody’s picture

Status: Needs review » Reviewed & tested by the community

#19 works great. Can we have a new release soon please, which contains this fix? That would be very very helpful.

samuel.mortenson’s picture

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

samuel.mortenson’s picture

Status: Reviewed & tested by the community » Needs work
geekinpink’s picture

FileSize
4.27 KB

Given patch was not applying on version entity_browser 8.x-1.1.
Added updated patch for this version.

carolpettirossi’s picture

#19 worked fine here as well. Any plans to a new release?

Thanks

samuel.mortenson’s picture

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

ZeiP’s picture

Status: Needs work » Reviewed & tested by the community

The 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!

slashrsm’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
3.32 KB
968 bytes

Few minor fixes.

slashrsm’s picture

Status: Needs review » Fixed

Committed. Thanks!

Liakoni’s picture

After i applied the patch #29 i got another error:

Fatal error: Using $this when not in object context in ... modules/entity_browser/src/Element/EntityBrowserElement.php on line 171

I tried in a field in form display and i got this error. In the editor it works fine.

Tsymi’s picture

Hi,

Error found on #32 has been fixed in this issue : https://www.drupal.org/node/2909945#comment-12264581

Status: Fixed » Closed (fixed)

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