// 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

borisson_ created an issue. See original summary.

jurcello’s picture

I 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:

/**
   * Add the path to the facets.
   *
   * @param \Drupal\facetapi\FacetInterface[] $facets
   * @return mixed
   */
  public function setFacetPaths($facets);

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:

/**
   * Get the path where the search is done.
   *
   * @return mixed
   */
  public function getPath();

The second option is easier to implement. I think we should try that one first.

borisson_’s picture

Issue summary: View changes

The second option seems like a better solution, added that in the IS.

borisson_’s picture

  • borisson_ committed f9b045c on 8.x-1.x
    Issue #2602274: Refactor FacetSourcePluginBase::fillFacetsWithResults
    

Status: Fixed » Closed (fixed)

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