We have one Ajax Links facet on a basic Search API View, and it is configured to limit the facet to one active item.

Selecting the facet has not been a problem. The issue is when unselecting the facet option to revert back to the original state. When doing so, the facet block "disappears." Upon closer examination, the block is getting a display: none applied to it.

Thoroughly debugged the code, and found the problem in the ajax_facets_process_facet_blocks function. The facet is being added to $blocks['hide_blocks'], when it should not be.

The problem is the function makes an incorrect assumption: there is always a value selected in "Search IDs" for the facet global settings.

This is not the right approach. The Facet API module does not require anything to be set for it to work properly. For example, this is a valid facet configuration:

Display for searches: "For all except the selected"
Search IDs: <None>

This configuration means all Search IDs are viable. It is also the equivalent of this configuration:

Display for searches: "Only for the selected"
Search IDs: <Select all>

Both of these options should be supported.

The issues occur in the area where there is a TODO replace it on facetapi_check_block_visibility() ?. The line shown here is never going to return a value for $facet->getBuild() when there is no Search ID selected in the facet:

if (!empty($builds[$group][$facet_name]) && $build = $facet->getBuild()) {

Tracing the issue back a bit further, the problem comes in when $adapter and $search_id are being set. When things are working correctly, there is a value for [current_search:protected]. When it is not working, the adapter array is empty.

Selecting Search IDs in the facet global settings fixes the issue.

=============

As a side note, found the same thing causes a problem for the Date Facets module: https://www.drupal.org/project/date_facets/issues/2220227#comment-13059299

Not selecting Search IDs causes an error in watchdog.

Comments

ron_s created an issue.