drupalfilterviewdrupal-8drupal-exposed-filter

Drupal 8 - Have a filter in a view which uses the node title of a node type


Hello fellow drupal users!

So, i have a 2 types of nodes, one is articles and the other is resources. In the article node, you can reference the resources nodes.

So i want to create a view, to filter the resources based on the title of the resource and based in the node in which the resource is used.

Example:

Article A - has the node reference for resource A, and resource B. Article B - has the node reference for resource B.

In the view, i want to be able to have a select which has the options: - Article A - Article B

If one of those options is selected, the view will show the resources that that article has referenced.

Is it possible? How can i do it?

Thanks in advance.


Solution

  • You'll have to use a relationship to achieve what you want. You do not need contextual filter as you want an exposed form to fill yourself the name of the article(s) you want the resources from.

    1. Create your view with a filter criteria "Content Type" set to filter Resources.
    2. In Advanced options, create a relationship to the contents that reference resources. The relationship will be in the Content category and be called something like "Content using field_XXX" where XXX is the name/label of your "Resources" field in your Article content type.
    3. Add a filter criteria that use the relationship you have previously created and which filters by Title. Configure it to be exposed to visitors and set as you wish (e.g. single filter, expose operator, etc).

    You may also want to use aggregation to avoid duplicates (Advanced->Other->Use aggregation).

    I hope it's what you were looking for.