Fatal error if passing a value of a facet with hierarchy and zero result in the URL

Created on 17 March 2022, almost 3 years ago
Updated 11 April 2023, over 1 year ago

Problem/Motivation

I have a "Team" facet with "use hierarchy" enabled. I also have the Facet Summary block added to the search page with that "Team" facet included. When I pass a value of the "Team" facet in the URL either manually or through a redirect from another page, however the 'team" with that value has zero result thus not showing in the "Team" facet dropdown options, the search page will crash with the following error:

The website encountered an unexpected error. Please try again later.
TypeError: Argument 2 passed to Drupal\Core\Link::__construct() must be an instance of Drupal\Core\Url, null given, called in /var/www/html/web/modules/contrib/facets/modules/facets_summary/src/FacetsSummaryManager/DefaultFacetsSummaryManager.php on line 167 in Drupal\Core\Link->__construct() (line 49 of core/lib/Drupal/Core/Link.php).

Proposed resolution

I tried to add a null check for Line 167 in the facets/modules/facets_summary/src/FacetsSummaryManager/DefaultFacetsSummaryManager.php file which fixed the crash:

if (!is_null($result->getUrl())) {
  $item = (new Link($item, $result->getUrl()))->toRenderable();
}

However, the Facets Summary block looks like this now:
• Reset
• Team: 7
• 0 results found
• (-) 7 (0)
I propose the second and fourth array to be moved from the Facet Summary block as above, and reset the URL maybe?

🐛 Bug report
Status

Active

Version

2.0

Component

Facet summary

Created by

🇺🇸United States wendychi

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.

  • 🇪🇸Spain eduardo morales alberti Spain, 🇪🇺

    Same here, I still debugging

  • 🇮🇳India chetananemade

    The patch is here!
    To fix the issue I've added the null check condition for '$result->getUrl()' at Line 185 in the facets/modules/facets_summary/src/FacetsSummaryManager/DefaultFacetsSummaryManager.php file which fixed the issue.

    I was facing this facet error issue when I'm selecting multiple values in one facet dropdown and then selecting values in another dependent facet dropdown means when its having zero results with combination of selections it throws error.

    This is ready to be reviewed.

Production build 0.71.5 2024