Error: Call to undefined method Drupal\Core\Entity\EntityFieldManager::getViewBuilder() in Drupal\search_api\Plugin\views\field\SearchApiEntity->getItem() (line 320 of search_api/src/Plugin/views/field/SearchApiEntity.php)

#0 search_api/src/Plugin/views/field/SearchApiEntity.php(273): Drupal\search_api\Plugin\views\field\SearchApiEntity->getItem(Object(Drupal\media\Entity\Media))

This completely breaks views based search pages with fields.

Comments

maximpodorov created an issue. See original summary.

maximpodorov’s picture

Status: Active » Needs review
StatusFileSize
new576 bytes
maximpodorov’s picture

Issue summary: View changes
ankithashetty’s picture

Have been facing this issue for the image field in the search view. The solution provided in #2 worked for me...

ankithashetty’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new20.57 KB

Patch in #2 applied successfully. Changing status to RTBC.

ressa’s picture

It would be great with the minimal steps required to reproduce the error, like "create a field of type XYZ, create a view using this field, etc.".

ankithashetty’s picture

StatusFileSize
new7.97 KB
new355.21 KB
new226.79 KB
new106.1 KB
new62.98 KB
new434.47 KB
new176.36 KB

Yeah sure @ressa, I'll list out the steps that I followed to encounter this error:

1. First, make sure you have created a search Index(/admin/config/search/search-api), with Datasource as "Content Type" and select the fields you would like to display on the search page.

2. In the Serach view, place the fields to be rendered on the search page.

3. Click on the Image field and choose the following configuration settings.

3 a. Uncheck the option "Use entity field rendering".

3 b. Under "Render settings", select "Entity View" option to Display Image bundle. Save the view.

4. Visit the search page (/search), you get the following error: (without the patch)

The website encountered an unexpected error. Please try again later.
Error: Call to undefined method Drupal\Core\Entity\EntityFieldManager::getViewBuilder() in Drupal\search_api\Plugin\views\field\SearchApiEntity->getItem() (line 320 of modules/contrib/search_api/src/Plugin/views/field/SearchApiEntity.php).

5. After applying the patch, refresh the search page, all fields are rendered properly. (with patch from #2)

Hope this helps! Thanks.

ressa’s picture

Thanks @ankithashetty! I followed your steps, initially using the "Article" "Image" field for testing: /admin/structure/types/manage/article/fields/node.article.field_image, but didn't see "Display for "Image" bundle" > "Entity View" (image 3 b.) under "Render settings" in the View ...

I tried enabling the Media module, and created an Image there, and now I seemed to get closer, getting a "Display for "Image" bundle" > "Entity View" in my View, which I could select, though there was no "View mode" > "Thumbnail" option ...

Perhaps this is mostly an issue with images from the Media module, or is it just that the default Article Image doesn't have a view mode defined?

Anyway, I now got the error in my searches, and preview in the View didn't work. After I applied the patch, the image showed in the results, not using "Use entity field rendering", but "Render settings" > "Display for "Image" bundle" in stead, and preview in my View worked, so the patch seems to do the job.

ankithashetty’s picture

Hey @ressa! Thanks for trying it out. And regarding the "View mode" > "Thumbnail" option you guessed it right, it's just a custom view mode I had created for Image Media type, so need not worry about that. Sorry for creating confusion there.

ressa’s picture

Thanks for clarifying, I guess all we can do now is wait for this issue to go to the next stages.

drunken monkey’s picture

Component: General code » Views integration
Priority: Critical » Normal
Status: Reviewed & tested by the community » Fixed

Thanks a lot for reporting this issue and providing a patch, maximpodorov, and thanks a lot to ankithashetty and ressa for explaining and reviewing so thoroughly!
This is very obviously a bug and the fix is very simple. I’m a bit bummed that we didn’t have test coverage for this, but I guess this specific problem is unlikely to resurface, and setting up the Media module for a Views test seems a bit overkill. So, happy to commit just the fix in this case.
Committed. Thanks a lot again, everyone!

ressa’s picture

Great, and thanks for maintaining the Search API module drunken monkey. Also thanks to ankithashetty and maximpodorov for patching and testing :-)

Status: Fixed » Closed (fixed)

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