Module throws an error if the first facet doesn't have any item in for a particular filter.

Fatal error: Call to a member function getUrl() on boolean in /var/www/*****/docroot/modules/contrib/facets/modules/facets_summary/src/Plugin/facets_summary/processor/ResetFacetsProcessor.php on line 61

Scenario:
1. We got one content type called product with two fields color and price.
2. Suppose out of many products one product color field is empty and the price is available.
3. And price facet shows two elements 100(2) and 200(1). And one item which is coming in 200 doesn't have color field filled.
4. If user select 200(1) in price facts then modules throws an error.

The module is trying to get the url from the first facet and for this face "Empty facet behavior" is set to "Do not display facet".

Comments

gulab.bisht created an issue. See original summary.

gbisht’s picture

Issue summary: View changes
gbisht’s picture

StatusFileSize
new919 bytes

The code is trying to run getUrl() on an empty array. The reason for this being empty is reset() which sets the pointer to the first item in the array and the first item is blank array as its empty and set to "Do not show facet".
Here is the patch to fix this issue.

gbisht’s picture

StatusFileSize
new919 bytes

Patch file updated.

borisson_’s picture

Status: Active » Needs review
Issue tags: +Needs tests

Setting to needs review, but will need a new test to prove that this actually fixes it.

borisson_’s picture

Status: Needs review » Needs work

Back to needs work for the test, so we can see that this actually fixes the behavior.

borisson_’s picture

Component: Code » Facet summary

Setting the component to facet summary.

We need to add a new test to \Drupal\Tests\facets_summary\Functional\IntegrationTest or extend ::testMultipleFacets in that class to actually test this.

borisson_’s picture

sylus’s picture

I have the other corresponding patch applied but occasionally I have fun into this exact same error.

The current patch did resolve my issues and I haven't been able to reproduce for the moment.

borisson_’s picture

@sylus @gulab.bisht: I don't have a live site with facets to test this on, I only have my dev-site and haven't seen this behavior yet. Would it be possible to add a test for this (or steps to reproduce that use core fields)

kamkejj’s picture

I ran into the same error and this patch fixed it. The site has commerce with a lot of products and not sure how to reproduce.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new2.4 KB

I can't reproduce this in a test.

Status: Needs review » Needs work

The last submitted patch, 12: fatal_error_on_first-2877004-12.patch, failed testing. View results

borisson_’s picture

Status: Needs work » Postponed (maintainer needs more info)

I can't reproduce this in the test I added, so until we get instructions on how to actually reproduce this in a testable way, we can't continue work on this.

mpp’s picture

We also experienced this issue.

We have a multilingual setup with 2 facets (hierarchical categories & tags).
As soon as a "tag" filter becomes active, we see the error, weirdly it doesn't occur for the "category" filter.

Here's our config:

langcode: en
status: true
dependencies:
  config:
    - search_api.index.poi
    - views.view.poi_index
  module:
    - search_api
id: poi_index_facet_summary
name: 'POI Facet Summary'
facets:
  tags:
    checked: true
    label: Tags
    separator: ', '
    weight: 0
    show_count: false
  category:
    checked: true
    label: Category
    separator: ', '
    weight: 0
    show_count: false
facet_source_id: 'search_api:views_page__poi_index__poi_index'
processor_configs:
  reset_facets:
    processor_id: reset_facets
    weights:
      build: '-10'
    settings:
      link_text: 'Clear filter'

Tags facet:

langcode: en
status: true
dependencies:
  config:
    - search_api.index.poi
    - views.view.poi_index
  module:
    - search_api
id: tags
name: Tags
url_alias: tags
weight: 0
min_count: 2
show_only_one_result: false
field_identifier: field_tags
facet_source_id: 'search_api:views_page__poi_index__poi_index'
widget:
  type: checkbox
  config:
    show_numbers: true
    soft_limit: 5
query_operator: and
use_hierarchy: false
expand_hierarchy: false
enable_parent_when_child_gets_disabled: true
hard_limit: 0
exclude: false
only_visible_when_facet_source_is_visible: true
processor_configs:
  active_widget_order:
    processor_id: active_widget_order
    weights:
      sort: -10
    settings:
      sort: ASC
  count_widget_order:
    processor_id: count_widget_order
    weights:
      sort: -9
    settings:
      sort: DESC
  display_value_widget_order:
    processor_id: display_value_widget_order
    weights:
      sort: -8
    settings:
      sort: ASC
  translate_entity:
    processor_id: translate_entity
    weights:
      build: 5
    settings: {  }
  url_processor_handler:
    processor_id: url_processor_handler
    weights:
      pre_query: -10
      build: -10
    settings: {  }
empty_behavior:
  behavior: none

Category facet:

langcode: en
status: true
dependencies:
  config:
    - search_api.index.poi
    - views.view.poi_index
  module:
    - search_api
id: category
name: Category
url_alias: category
weight: 0
min_count: 1
show_only_one_result: false
field_identifier: field_category
facet_source_id: 'search_api:views_page__poi_index__poi_index'
widget:
  type: checkbox
  config:
    show_numbers: true
    soft_limit: 0
query_operator: or
use_hierarchy: true
expand_hierarchy: false
enable_parent_when_child_gets_disabled: false
hard_limit: 0
exclude: false
only_visible_when_facet_source_is_visible: true
processor_configs:
  count_widget_order:
    processor_id: count_widget_order
    weights:
      sort: -9
    settings:
      sort: DESC
  display_value_widget_order:
    processor_id: display_value_widget_order
    weights:
      sort: -8
    settings:
      sort: ASC
  translate_entity:
    processor_id: translate_entity
    weights:
      build: 5
    settings: {  }
  url_processor_handler:
    processor_id: url_processor_handler
    weights:
      pre_query: -10
      build: -10
    settings: {  }
empty_behavior:
  behavior: none
mpp’s picture

Status: Postponed (maintainer needs more info) » Needs work
dragos-dumi’s picture

Assigned: Unassigned » dragos-dumi
Issue tags: +Vienna2017
dragos-dumi’s picture

Status: Needs work » Needs review
StatusFileSize
new2.77 KB
new4.27 KB

Attached test to reproduce the error and the patch to fix this - different solution than #4
removing using the first facet item link - using uri from request.

    $url = Url::fromUserInput($request->getRequestUri());
    $url->setOptions(['query' => $query_params]);

The last submitted patch, 18: facets-error-reset-link-test-only.patch, failed testing. View results

borisson_’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

This looks really great! Thanks @dragos-dumi!

borisson_’s picture

Status: Reviewed & tested by the community » Fixed

  • borisson_ committed bc36d3f on 8.x-1.x authored by dragos-dumi
    Issue #2877004 by gulab.bisht, dragos-dumi, borisson_: Fatal error on...

Status: Fixed » Closed (fixed)

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