diff --git a/src/Plugin/facets/facet_source/SearchApiDisplay.php b/src/Plugin/facets/facet_source/SearchApiDisplay.php index 37e5e0b..c0e74e7 100644 --- a/src/Plugin/facets/facet_source/SearchApiDisplay.php +++ b/src/Plugin/facets/facet_source/SearchApiDisplay.php @@ -19,6 +19,7 @@ use Drupal\search_api\FacetsQueryTypeMappingInterface; use Drupal\search_api\Query\ResultSetInterface; use Drupal\search_api\Utility\QueryHelperInterface; +use Drupal\taxonomy\TermInterface; use Drupal\views\Views; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -282,7 +283,34 @@ public function fillFacetsWithResults(array $facets) { * {@inheritdoc} */ public function isRenderedInCurrentRequest() { - return $this->getDisplay()->isRenderedInCurrentRequest(); + $display = $this->getDisplay(); + $is_page = $display->isRenderedInCurrentRequest(); + + // This is the page display for the selected view. + if ($is_page) { + return TRUE; + } + + // It is still possible that the source is displayed on the page using TVI. + if ($this->moduleHandler->moduleExists('tvi')) { + if (str_starts_with($display->getBaseId(), 'views_')) { + $term = \Drupal::routeMatch()->getParameter('taxonomy_term'); + if ($term instanceof TermInterface) { + $tvi = \Drupal::service('tvi.tvi_manager'); + $term_view = $tvi->getTaxonomyTermViewAndDisplayId($term); + if (!empty($term_view) && isset($term_view['view_id'], $term_view['display_id'])) { + $display_plugin_definition = $display->getPluginDefinition(); + if (isset($display_plugin_definition['view_id'], $display_plugin_definition['view_display'])) { + if ($term_view['view_id'] == $display_plugin_definition['view_id'] && $term_view['display_id'] == $display_plugin_definition['view_display']) { + return TRUE; + } + } + } + } + } + } + + return FALSE; } /**