0

My site's users have an entity reference field in their profile called "Club" where they select which Club they are a member of. Similarly, when creating a Project (a content type) you can select which club created it. I am trying to create a view called "My Club's Projects" which only shows the Projects created by the club the user has selected in their profile.

I am frustrated because when I try to create a Contextual Filter, my only options are to get parameters from the URL or use the ID of the logged in user. There is no option to use a field from the current user's profile as the contextual filter, which is what I want. No matter how many relationships I add, these options do not change. How do I add a contextual filter based on the current user's club, rather than their ID?

EDIT: I've seen many answers that reference a relationship called "Taxonomy term referenced from field_[mytaxonomy]". In my case, I am not using a taxonomy term, but an entity reference; the only available relationship using this field is "Users using field_club_entity_reference". I was hoping to find something like "Content referenced from field_club_entity_reference", but no such relationship exists.

EDIT 2: I've implemented @prkos' suggestions, details of the View setup as follows. It's a View that displays content with type Project.

Relationships:

  • field_club: Content (the Club entity reference from the Project content type)
  • (field_club: Content) field_club_entity_reference (the Club entity reference from the User account, using the first relationship)

Contextual Filters:

  • (field_club_entity_reference) User: Club:target_id with default value set to User ID from logged-in user.

No other filters other than the standard Content: Published (= Yes) and Content: Content type (= Project).

Unfortunately the view still displays no results. It should be displaying two projects for my account since there are two projects that have the same club selected as my account does.

  • 2
    Possible duplicate of Filter taxonomy term attached to user field – prkos Aug 2 at 17:55
  • The matching is done with Relationships because you're matching from two different tables in db and Views always use one table as base. When you introduce the new data through Relationships, then you can use Contextual filering the usual way: drupal.stackexchange.com/questions/281058/… – prkos Aug 2 at 17:57
  • @prkos I saw that, but step 2 references a relationship called "Taxonomy term referenced from field_[mytaxonomy]". In my case, I am not using a taxonomy term, but an entity refernce; the only relationship using this field is "Users using field_club_entity_reference". I was hoping to find something like "Content referenced from field_club_entity_reference", but no such relationship exists. Edited my post to include this. – Henry Floyd Aug 2 at 18:47
  • Is Club a CT? Then you should have this Relationship available: "Content referenced from field_club_entity_reference" if you're starting from Views of the Content type, listing Projects. You've probably created a User type Views, that's why there's no such Relationship there, you need to create Views of type Content. What's the name of your Entity Reference field on the Product CT? Maybe you're searching for the wrong name in Relationships. – prkos Aug 2 at 20:06
  • @prkos Yes, Club is a content type. My view is displaying Projects, also a content type. The club entity reference field on the Project is called field_club, the club entity reference on the User is field_club_entity_reference. Should I be adding a relationship to field_club instead (the field in Project)? If so, how does that help my choice of Contextual Filters? The link above references a "User ID" contextual filter, which I also do not have. When I search "user" in contextual filters, all I get are "Authored by" and "User has a revision". – Henry Floyd Aug 2 at 23:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.