Call to a member function getDataDefinition() on bool

Created on 19 March 2022, over 2 years ago
Updated 20 September 2024, 2 months ago

Problem/Motivation

I'm not sure the exact scenario that causes this error but I got the following error

The website encountered an unexpected error. Please try again later.
Error: Call to a member function getDataDefinition() on bool in Drupal\facets\Plugin\facets\processor\ListItemProcessor->build() (line 128 of modules/contrib/facets/src/Plugin/facets/processor/ListItemProcessor.php).

I think this stems from the $field variable being potentially `FALSE` while `elseif ($field->getDataDefinition() instanceof FieldItemDataDefinition) {` is run on it.

Proposed resolution

Adding a check that $field isn't == FALSE.

elseif ($field && $field->getDataDefinition() instanceof FieldItemDataDefinition) {

🐛 Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

🇺🇸United States bfodeke

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.

  • 🇧🇪Belgium kenowax Mons

    I've had the same issue using exposed filters on views and the following modules : facets, core_views_facets.

    For some reason, when creating a facet for an exposed filter on a List and ticking the "Show labels instead of values" in the facet config, the facets module tries to load the field postpended with "_value" in the facets\Plugin\facets\processor\ListItemProcessor class.
    This does not exist in the base field definitions so the instantiated $field = FALSE; variable at the start of the function stays at FALSE.

    Your patch does avoid the use of a function on FALSE, the original error.
    However, the facets does not load the field labels correctly, it gives the values instead.

  • 🇧🇪Belgium kenowax Mons

    After further investigating, I have found that the module loads the "node" base field definitions which cannot contain all the necessary fields, for example if you have a TextList field in a custom content-type.

    Therefor, it is impossible to get the original field definition without first getting the actual bundle.

    I do believe this goes beyond the original intent of this issue.

    Anyways, the fix does work.
    Thank you for sharing !

  • Status changed to Needs work 7 months ago
  • 🇺🇸United States smustgrave

    Think this needs a different approach, think we need to figure out why none of the field conditions before this were triggered to set the $field variable. Feel this check is just masking a larger issue potentially.

  • 🇮🇳India prashant.c Dharamshala

    I was facing this issue when adding Select list field as a Facet.

  • 🇩🇪Germany Anybody Porta Westfalica

    I can also confirm this issue. Unsure when I visited the settings page for the last time, but I'm on 3.0.x currently, so I'm changing the version to the latest one.
    Maybe this was even caused by update in my case?

Production build 0.71.5 2024