0

I really would need some help with contextual filter.

I have a content type I use for products, different kind of security cabinets. In this particulary case it is aboyt burglary safes. They have a classification of 0,1,2,3,4,5, S1 or S2. So all burglary safes has one of these classes. To give them the class I have created a Vocabulary with the name "Burglary Classes" and there I have created the classes 0,1,2,3,4,5, S1 or S2 as terms.

In Views I have made a block with a table presenting all burglary safes, containg fields like dimensons and weight and so on and have brought in this table block to the Content type, as a field, and it works just fine.

Now to my question; All products in the Content type are not burglary safes so some are not classified according to 0,1,2,3,4,5, S1 or S2 , but I can't firgure out how to configure the Contextual filter.

I want ALL safes classifed to ANY of the terms 0,1,2,3,4,5, S1 or S2 to appear in ALL of the nodes having ANY of the terms 0,1,2,3,4,5, S1 or S2 but NOT to appear in any other node

The best shot I have had is filtering so that in the node only products belonging to the same Burglary Class as the node itself, appears. But as said, I want all products with a burglary class to appear.

Greatful for your help

Hans

(On request I have tagged the question for Drupal 7! Sorry for forgetting)

1
  • Could you tag this with either a 7 or an 8 to designate which Drupal version? Dec 21, 2017 at 12:37

1 Answer 1

0

Have you looked at the PHP filter module? I believe you could make two views, one which displays the burglary safe items and one which displays the non-burglary safes. Add both blocks to all pages, then use the filter module with a PHP expression to decide which to make visible and which invisible.

12
  • Thanks, but I don't know how to code in PHP. So you are telling me it can't be done in a "normal" way, with the standard features? The problem with your solution is that the issue will reocceur for many other products. It seem to be an issue that a product can belong to more than one category, or terms, in the same vocabulary. Maybe I have to look on how I orgainze the Vocabularies.
    – hassebasse
    Dec 21, 2017 at 20:15
  • There very well could be a way to do this. I am not an expert in Drupal by any means and know more about Drupal 8 then 7. However, I did know of the PHP filter feature and thought it might work in your case. The only other options I would have would involve writing a custom module, which would involve PHP. Dec 21, 2017 at 22:27
  • Thanks you for your input. Isn't there a way to filter on single terms in a given vocabulary? It should work in my case because I have a Vocabulary named "Categories" and there I have terms like "Burglary safes", "Storage of flamable liquids", "Fireproff filing cabinets" etc. If so, I then could make a contextual filter that makes all burglary safes pop up on nodes with Burglary safes.
    – hassebasse
    Dec 22, 2017 at 9:01
  • Here's how i interpret your question. Let's say you have an entity with id=4 classified with taxonomy term t_id=6. When a user visits /entity/4 you would like to see all entities that are classed with t_id=6. I cannot think of an out of the box way to get views to do this. The issue arises because you have to step up a level, then back down.You are stepping from entity, to taxonomy, back down to entity. The views relationships only work by continuing to step up. It would not be too difficult to program a contextual filter to do this though if you have someone to go to. Dec 22, 2017 at 14:30
  • 1
    This is the correct English name of the filter: "Has taxonomy term ID (with depth)"
    – hassebasse
    Dec 26, 2017 at 18:15

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.