Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
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
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:
- 8.x-1.x changes, plain diff MR !60
- 3270514-function-on-bool changes, plain diff MR !61
Comments
Comment #2
bfodeke CreditAttribution: bfodeke at Red Hat commentedComment #6
mkalkbrennerComment #7
KenowaX CreditAttribution: KenowaX commentedI'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.
Comment #8
KenowaX CreditAttribution: KenowaX commentedAfter 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 !