Skip to content
Snippets Groups Projects

Issue #2873480: Facet Summary for Facet Items with a set dependency

Open Issue #2873480: Facet Summary for Facet Items with a set dependency
2 unresolved threads
Open Alexandre Dias requested to merge issue/facets-2873480:2873480-summary into 2.0.x
2 unresolved threads
Files
5
@@ -9,6 +9,7 @@ use Drupal\facets\Event\ActiveFiltersParsed;
use Drupal\facets\Event\QueryStringCreated;
use Drupal\facets\Event\UrlCreated;
use Drupal\facets\FacetInterface;
use Drupal\facets\FacetManager\DefaultFacetManager;
use Drupal\facets\UrlProcessor\UrlProcessorPluginBase;
use Drupal\facets\Utility\FacetsUrlGenerator;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -49,14 +50,22 @@ class QueryString extends UrlProcessorPluginBase {
*/
protected $urlGenerator;
/**
* The default Facet manager.
*
* @var \Drupal\facets\FacetManager\DefaultFacetManager
*/
private $facetManager;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, Request $request, EntityTypeManagerInterface $entity_type_manager, EventDispatcherInterface $eventDispatcher, FacetsUrlGenerator $urlGenerator) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, Request $request, EntityTypeManagerInterface $entity_type_manager, EventDispatcherInterface $eventDispatcher, FacetsUrlGenerator $urlGenerator, DefaultFacetManager $facet_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $request, $entity_type_manager);
$this->eventDispatcher = $eventDispatcher;
$this->urlGenerator = $urlGenerator;
$this->initializeActiveFilters();
$this->facetManager = $facet_manager;
}
/**
@@ -70,7 +79,8 @@ class QueryString extends UrlProcessorPluginBase {
$container->get('request_stack')->getCurrentRequest(),
$container->get('entity_type.manager'),
$container->get('event_dispatcher'),
$container->get('facets.utility.url_generator')
$container->get('facets.utility.url_generator'),
$container->get('facets.manager')
);
}
@@ -112,6 +122,22 @@ class QueryString extends UrlProcessorPluginBase {
}
}
// Get dependent facets that have to be removed with active values.
$dependent_facets_aliases = [];
$this->facetManager->processFacets($facet->getFacetSourceId());
$facets = $this->facetManager->getFacetsByFacetSourceId($facet->getFacetSourceId());
foreach ($facets as $other_facet) {
$config = $other_facet->getProcessorConfigs();
if (empty($config['dependent_processor']['settings'][$facet->id()]['enable'])) {
continue;
}
/* @var \Drupal\facets\Plugin\facets\processor\DependentFacetProcessor $dependent_processor */
$dependent_processor = $other_facet->getProcessors()['dependent_processor'];
if ($dependent_processor->isConditionMet($config['dependent_processor']['settings'][$facet->id()], $facet)) {
$dependent_facets_aliases[] = $other_facet->getUrlAlias();
}
}
/** @var \Drupal\facets\Result\ResultInterface[] $results */
foreach ($results as &$result) {
// Reset the URL for each result.
@@ -143,6 +169,12 @@ class QueryString extends UrlProcessorPluginBase {
if ($filter_param === $filter_string || ($filter_missing && str_starts_with($filter_param, $filter_missing))) {
unset($filter_params[$key]);
}
// Also remove dependent facets.
$filter_key = explode($this->getSeparator(), $filter_param);
if (in_array($filter_key[0], $dependent_facets_aliases)) {
unset($filter_params[$key]);
}
}
if ($facet->getUseHierarchy() && !$result->isMissing()) {
$id = $result->getRawValue();
Loading