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) {

Issue fork facets-3270514

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bfodeke created an issue. See original summary.

bfodeke’s picture

Issue summary: View changes

mkalkbrenner’s picture

Version: 8.x-1.8 » 2.0.x-dev
Status: Active » Needs review
KenowaX’s picture

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 TextList and ticking "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.

KenowaX’s picture

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 !