0

This seems like a logical use case, but I cannot find any information about how to do this. I am creating a large, number of pages, site and want to use Solr Indexed data on the Taxonomy Term pages. The indexed content is not available in the normal Taxonomy Term view page. Any suggestions on how to create this?

(A) I have tried using a view of indexed data and then trying to set the path to the taxonomy term page using a contextual filter with the term ID. But the Content: Has term ID contextual filter is not an option with and indexed data view.

(B) I tried creating a aggregated field of the term ID's hope I could use those to pass to the path, with no success.

1 Answer 1

-1

I'm not sure the following is the only solution.

I follow Your first approach:

  1. Create a view;
  2. Create a page;
  3. Set the path to taxonomy/term/% (assuming You disabled the "normal" taxonomy page);
  4. In advanced→contextual filers add the reference fields to the taxonomies (assuming those fields are included in the SOLR index);
  5. Set those contextual filters to use as predefined value the ID of the taxonomy from the URL.

Now, this might not work out of the box since the contextual filters will be processed as an AND condition (I think this is the default), therefore no results will be displayed.

Create some custom module (if you don't already have one) and include some code like:

/**
* Implementation of hook_views_query_alter().
*/
function your_module_views_query_alter(Drupal\views\ViewExecutable $view, Drupal\views\Plugin\views\query\QueryPluginBase $query) {

    $target_view_name = 'the_view_machine_name';
    $target_display_id = 'the_display_machine_name';

    if ($view->id() === $target_view_name && $view->current_display === $target_display_id) {

        $where = &$query->getWhere();
        $where[0]['type'] = 'OR';
    }
}

Don't forget to clear the caches.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.