0

I am trying to create a view that to show content classified by taxonomy term and the hierarchy level of the logged in user within that taxonomy vocabulary.

For instance, the content is organized in 10 different levels of a taxonomy ranking, and each user is progressing through each level of that taxonomy (in an educational pathway), and we want to show all content of those levels that the user has reached and could have possibly have gone through up to that point.

For example if the user has reached level 5 (or has been given that rank by admin), the view will show all content for levels 1 through 5, but not anything higher. If user is level 7, then the view will show all content with taxonomy 1 through 7 but nothing higher.

How can I do that? How can I reference the user in a view and take their taxonomy term to limit the view's content based on that?

  • Welcome to Drupal Answers! A little bit broad your question to be honest. You have to create a relationship to the current user I think, then add a filter based on their terms. I think you then also have to override that filter programmatically somehow taken the term weights into account as I'd guess this can't be done just from the UI. – leymannx Jan 3 at 11:20
  • Hello, thanks for reply and sorry for sounding to broad, but yes I was thinking that "weight" of the term in relationship to logged in user is the key to doing that, but I am unable to see how to define the value field within the views admin. While I know how to create a filter for weight, and there are operators for "less than or equal to" , I have used specific values before but unsure what to place in the "value" field for this type of reference operation. *unfortunately I am not a coder and just work with drupal admin, so trying to keep this all through views. thanks – DJS Jan 3 at 21:02
0

To control access to your content based on taxonomy terms you need to use modules like Taxonomy Access Control or Permissions by Term. With proper configuration these will prevent users from viewing content they don't share terms with, even if they can guess the content links for example.

You can create Views that lists content based on shared taxonomy terms, but Views don't control access to original nodes pages. If a user can guess the node paths, or you have content listed on Taxonomy pages and the Taxonomy pages aren't access-controled then they will be able to see the content links there and click through.

Using one of those modules you will be able to control access through terms alone, or you may need to create a new user Role for each term, it depends on your details.

Once you solve the Permissions problem you can create Views that would show content that the current user shares terms with.

The easiest way to approach this is not to rely on weight/order at all. You can treat terms like badges: if a user reaches 3rd level, they would be tagged with the first 3 terms, and not only the third term. Drupal doesn't care if you name them "level-1" and "level-2" or "beginner" and "medium". You just have to make sure to add terms to the user once they pass a level, and keep all the terms they "collected" before.

If you go for only the one highest term they have reached you have to take care of the removing the current term when a new one is reached, it introduces complexity that isn't necessary if you're relying on taxonomy terms.

There are still ways to show only the highest term if you want to use it to rank a user.

To create a page showing content that the current user shares terms with you use Relationships to the taxonomy reference field. The details are almost the same as in this QandA: Based on user's country filter content of same country?

  • Thanks much for the feedback an I do like this direction! This seems best way to handle the content access for sure. However, do you know an easy way for me to be able to feature the highest level reached within the hierarchy of terms which would be for use in the users profile to mark their progress (for themselves and for teachers). In our situation they will be keeping all terms as the progress through the levels, however, their current rank is important to have set. thanks much! – DJS Jan 4 at 19:50
  • One way to show only the term a user is tagged with that has the lowest weight in its Vocabulary is to create a Views Block listing users, with the Taxonomy field set NOT to display "Display all values in the same row", limit the number of items to show to 1, add a Contextual filter for the user ID, add the Relationship to the term through the reference field, and then you'll be able to add Sorting criteria (field_tags: Taxonomy term) Taxonomy term: Weight (desc). Then place the Block to be visible only on user profiles. This relies on the order of terms in Vocabulary, not on user profile! – prkos Jan 5 at 1:33
  • Thanks prkos, that makes sense. And am guessing that if I change the weight sort from desc to ascending, I will be able to get the highest level reached as the primary visible. I will give it a whirl! thanks again – DJS Jan 5 at 5:36
  • So, for the modules like Taxonomy Access Control or Permissions by Term is there a way to get the permissions to be based off some kind of reference to this matching rank term that we are going to have for the users? After looking it seems that those modules will grant the permission by roles and individual users for the terms, however, we are going to have a vast number of terms so don't want to setup additional roles for each of them, and don't want to authorize each individual user to a vast amount of terms either. If there is something I am missing your input is appreciated! – DJS Jan 5 at 7:41
  • Asc or Desc depends on how you order your terms, I assumed they start with lowest level on top, but if you have them highest level on top then use Asc. I don't have insight into configuration details but I expect you won't have to create user roles. From permissions_by_term page: "Articles related to the taxonomy term are created by the teacher and only visible to the students related to the taxonomy term." – prkos Jan 6 at 2:36

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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