Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
// If our results are not there, execute the view to get the results.
if (!$results) {
// If there are no results, execute the view. and check for results again!
$view = Views::getView($this->pluginDefinition['view_id']);
$view->setDisplay($this->pluginDefinition['view_display']);
$view->execute();
// Set the path of all facets.
// @todo Does that need to happen here?
$path = $view->getDisplay()->getOption('path');
if ($path) {
foreach ($facets as $facet) {
$facet->setPath($path);
}
}
$results = $this->searchApiResultsCache->getResults($this->pluginId);
}
Setting the path to the facet is better done in another place.
Todo
- The facetsource interface (and implementation) should be extended with a
getPath();
method. - In the facetManager, we should call out to the facet source
Comments
Comment #2
jurcello CreditAttribution: jurcello at Triquanta commentedI think the best place to do this is in a new method called setFacetPaths($facets) on the facet source.
The source should know the path of the facets. So in the interface the method could be added:
Another possibility is that the manager add's the path to the facet. Than the only thing the source has to do, is to return the path:
The second option is easier to implement. I think we should try that one first.
Comment #3
borisson_The second option seems like a better solution, added that in the IS.
Comment #4
borisson_This fix means that #2598902: Add 'show only on a page that contains the facet source' setting and a second facetsource plugin to include view blocks needs a reroll as well as https://github.com/swentel/search_api_page/pull/1.
This might affect #2603572: Create a SearchApiBaseFacetSource class. as well.