How to tell if the current page is using TVI?

Created on 3 April 2025, 4 days ago

I'm working on allowing TVI integration on the Facets module so TVI-added views displays can be used with Facets ( πŸ’¬ Default display of view cannot be used as a facet source Active }. Is there any way to tell whether the current route is configured to display a views display using TVI?

πŸ’¬ Support request
Status

Active

Version

2.0

Component

Miscellaneous

Created by

πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @DamienMcKenna
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    This is the code I'm prototyping:

    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;
              }
            }
          }
        }
      }
    }
    

    It feels a bit unclean, besides the \Drupal::service() usage. Is there a better way?

Production build 0.71.5 2024