1

I try to make a relation between two reference fields inside one node. For example, this node (type: groups) I've created:

Example (node) 1:

Group 1 has two users and one course

-- Reference field: Users
--- User 1
--- User 2

-- Reference field: Courses
--- Information technology

Example (node) 2:

Group 2 has one user and one course

-- Reference field: Users
--- User 2

-- Reference field: Courses
--- Psychology

Currently I'm using views for it. My goal is, if a user is logged in, all courses are showing up which is associated with his group.

Group 1: User 1 and User 2 should both see the course: Information Technology.
Group 2: User 2 should also see: Psychology.

I'm not sure if this is possible with views and if my current structure is right?

5
  • You will probably need a views contextual filter drupal.org/docs/8/core/modules/views/… and perhaps a relationship drupal.org/docs/8/core/modules/views/…. Here is a simple contextual filter to understand to get you started wishdesk.com/blog/drupal-8-views-contextual-filters. This module drupal.org/project/user_field_value might also be helpful. Please try to setup your view and contextual filters and update the post with the details.
    – GiorgosK
    Nov 6, 2020 at 19:16
  • Here is another similar contextual filter question you might want to try to understand drupal.stackexchange.com/questions/277569/…
    – GiorgosK
    Nov 6, 2020 at 19:22
  • Yes it can be done with Views, as can many other structure combinations. I'd start with a list of Courses, add the Reverse Relationship for the group (Courses field), add another Relationship, for the Users (referenced from the group), make it use the first Relationship, require both. Then add a Contextual filter for the user ID that uses the second Relationship and set a default value from the logged in user context. You can find similar answers that do something similar where you can learn what the steps mean.
    – prkos
    Nov 6, 2020 at 22:36
  • Thank you guys, I figured it out the way you told me @prkos. Nov 7, 2020 at 10:27
  • You can add your answer to help others with the same problem ;)
    – prkos
    Nov 7, 2020 at 14:52

0

Your Answer

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

Browse other questions tagged or ask your own question.