There used to be 1 facet manager for every facet source.
Now we changed the this, and there is only one manager for all sources. This manager should be able to handle more than one source in one request (although this might be a rare situation).
The implementation right now feels buggy: what happens when two sources are active at the same time?
What needs to be done is the following:

- remove the protect variable facetsource_id from the manager.
- add a protected variable (array of facet sources) to hold all the facetsources that are used during the request.
- Refactor manager::alterQuery to alterQuery(&$query, source_id) so the query object is only fed to facets using the source_id facetsource.
- Refactor manager::updateResults(): each facetsource used in the request should be able to add the results to it's facet.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jurcello created an issue. See original summary.

ChristianAdamski’s picture

Version: » 8.x-1.x-dev
Category: Task » Bug report

I just ran into this. "My" core views integration provides two sources, one for exposed filters and one for contextual filters (thats GET parameters and URL parameters). There is a good chance one would want to use both mixed on the same page. And it fails, because the first source gets handed all facets to process, even the ones not belonging to it.

ChristianAdamski’s picture

Status: Active » Needs review
FileSize
11.65 KB

Let's see what testbot has to add.

ChristianAdamski’s picture

Removed the entire set/getFacetSourceId stuff. The manager is able to handle this by the facets it knows about.

borisson_’s picture

Status: Needs review » Needs work

A couple of smaller issues.

  1. +++ b/facets.module
    @@ -36,7 +36,6 @@ function facets_search_api_query_alter(QueryInterface &$query) {
    -  $facet_manager->setFacetSourceId($search_id);
    -  $facet_manager->alterQuery($query);
    +  $facet_manager->alterQuery($query, $search_id);
    

    This changes makes sense and looks great.

  2. +++ b/src/FacetManager/DefaultFacetManager.php
    @@ -71,16 +71,17 @@ class DefaultFacetManager {
       /**
    -   * A boolean flagging whether the facets have been processed, or built.
    +   * An array of boolean flagging whether the facets have been processed,
    +   * or built, sorted by facet source.
        *
        * This variable acts as a semaphore that ensures facet data is processed
        * only once.
        *
    -   * @var boolean
    +   * @var array
        *
        * @see FacetsFacetManager::processFacets()
        */
    -  protected $processed = FALSE;
    +  protected $processedFacetSources = [];
    

    https://www.drupal.org/coding-standards/docs

    All summaries (first lines of docblocks) must be under 80 characters, start with a capital letter, and end with a period (.). They must provide a brief description of what a function does.

    That means the first line of the docblock is now too long, I also think we should use @var bool[] to indicate that this is an array of booleans.

  3. +++ b/src/FacetManager/DefaultFacetManager.php
    @@ -248,11 +246,11 @@ class DefaultFacetManager {
    +   * @return array Facet render arrays.
    +   * Facet render arrays.
    +   * @throws \Drupal\facets\Exception\InvalidProcessorException
    

    The @return here isn't formatted as it should be:

    @return array
      Facet render array
    
    
  4. +++ b/src/FacetManager/DefaultFacetManager.php
    @@ -260,9 +258,7 @@ class DefaultFacetManager {
    +    $facet_source_id = $facet->getFacetSourceId();
    

    Didn't we remove this method?

  5. +++ b/src/FacetManager/DefaultFacetManager.php
    @@ -316,14 +312,19 @@ class DefaultFacetManager {
    +   * @param $facetsource_id
    +   *   The facet source ID of the currently processed facet.
    

    @param string $facetsource_id

  6. +++ b/src/FacetManager/DefaultFacetManager.php
    @@ -334,15 +335,15 @@ class DefaultFacetManager {
    -   * @param string $facet_id
    -   *   The id of the facet.
    +   * @param FacetInterface $facet
    +   *   The facet to process.
        *
    -   * @return \Drupal\facets\FacetInterface|NULL
    +   * @return FacetInterface|NULL
    

    This needs to be the full namespaced version.

ChristianAdamski’s picture

Before I start to handle this:

1.) I use this alot! Is this realy removed? Not in current git at least.

$facet_source_id = $facet->getFacetSourceId(); 
Didn't we remove this method?

2.)

This needs to be the full namespaced version.

I removed a lot of those. Do I get this right, that in the @param parts, we always want the full namespace? Or just in that one location?

borisson_’s picture

re: #6:

  1. didn't you just say that in #4?
  2. In the documentation we need to use FQDN, yes.

    Always prefix types with the fully-qualified namespace for classes and interfaces (beginning with a backslash). If the class/interface is in the global namespace, prefix by a backslash.

    https://www.drupal.org/coding-standards/docs

ChristianAdamski’s picture

6.1. > Ah, ok. *phew* I removed that get/set FacetSource stuff from the Defaultmanager. The facets themself still need those alot.

6.2. > Oh boy. I was a bit trigger happy there because PHPStorm asked so nicely. Restoring them...

ChristianAdamski’s picture

Status: Needs work » Needs review
FileSize
13.53 KB

Ok, should fix all your remarks.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

This looks great.

borisson_’s picture

Status: Reviewed & tested by the community » Fixed

Awesome, thanks!

Status: Fixed » Closed (fixed)

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