I have a content type called Documents that includes an entity reference field. That entity reference is connected to a Course content type so that the user, when adding a document, can select one or more courses that the document applies to.

I want to create a block view to display those documents relating to a specific course on that course page.

So I have Course A and Course B. And I have numerous documents, some where Course A is selected in the Entity Reference field, some where Course B is selected, and some where both courses are selected.

I want to display those documents associated with Course A on Course A's page using a block view. Same for Course B.

I know this has to do with Contextual Filters and Relationships but I'm not quite coming up with the correct settings and would appreciate some help.

Comments

Lloyd’s picture

Status: Active » Closed (works as designed)

solved

sondes’s picture

I'm looking for a solution to a similar problem. Could you describe how you made this block view work?

Thanks!

chOP’s picture

Lloyd, how about a link to the information that helped you solve this?

Lloyd’s picture

I forget where I found the info that helped but here is what I did:

CONTENT TYPE

Course

: Each course we offer is handled by creating a node using the Course content type

Document

: Individual documents are uploaded into Drupal
Custom Field: Entity Reference to Course content type

GOAL

I wanted to be able to upload a document and associate it with one or more courses. Then, using a View I want to display the documents relating to a specific course on that course page using a Block. A document can be associated with one or more courses.

VIEW

Filter

Content: Type = Course Page

Contextual Filters

One contextual filter as follows:

Relationship: Do not use a relationship
When the filter value is not available: Provide default value - Type = Content ID from URL

Relationships

One relationship as follows:

Entity Reference: Referencing Entity
A bridge to the Content entity that is referencing Content via field_related_course_page
Do not use a relationship
field_related_course_page is the custom entity reference field in the Document content type

Fields

Document: Document URL

Relationship: Content referencing Content from field_related_course_page

Content: Title

Relationship: Content referencing Content from field_related_course_page

Note: The key in fields is the relationship. Obviously you can use whatever fields you like but you need to have the correct relationship.

I tried different approaches and this was the only one I could figure out that worked.

sondes’s picture

Thanks Lloyd! I'm using essentially the same approach and it's working well.

I'm also looking for a way to filter out the current node from the list of other referenced nodes. I think in your case it would be something like filtering out the Document that the user is currently viewing. So a list of Documents would include all Documents except the currently viewed one.

Anyone have any ideas? Thanks!

stephesk8s’s picture

Thank you Lloyd. A simple write-up and a big help. :)

EdPhillis’s picture

When you say

One contextual filter as follows:

Relationship: Do not use a relationship
When the filter value is not available: Provide default value - Type = Content ID from URL

what exactly are you contextually filtering?? you only get 'relationship: do not use a relationship' if you are going to filter on something....apart from that it looks like a good step by step.

dularion’s picture

Issue summary: View changes

Like derek smalls says, what field is your contextual filter filtering on?

kualee’s picture

In case anyone else still come upon this page on Google search like me, the contextual filter is filtering on Content:Nid field

edrigor29’s picture

For example, you were tasked to build a Forum that does cross-listing users according to their geolocation.

So, we have a content type called Forum that includes all the necessary fields like entity reference and taxonomy. That entity fields are connected to that forum content type.

So the way to do it

We can actually determine the cross-listing the moment the user logged in and choose the right location, and that location we'll use it as a location ID (base on Continent and not base on the Country) That continent will be use as a block (Contextual Filter) to be use as a parameter, once it gets fired or click by the the user, lets say the User chooses "Asia" all that comes out inside the forum will be only "Asia" and i'll place also a exposed filters for the Category [ Education, Science, Ecosystem, etc.] and label it as Category above the Forum. So it will be easy for the user to go choose a category they wanted to go or look at to read.

So for the Continent block, i'll use relationship, Adding relationships using the Location Id, not the author id. So, now that location id will be the Identifier, and go back to Contextual Filter and hit "add" choose location id, and the User: Location Id.

Above there is a Relationship that holds the Location id as the identifier. In the forum page, i'll select the "Validator as User" in the "Type of user filter value to allow: select "only allow string usernames".

SetUp:

- Setup location Id of the User to use as a Contextual Filter to use as parameter to the forum content type by grabbing or declaring the node to make a bridge that once that geolocation (continent) gets fired it sends us to directly to the forum according by Continent, and the topics within that Continent.

- Forum View, set up all the necessary fields and formats within this View.

I'll use Contextual Filter and Relationship to bind the Content type "Forum" and also the users geolocation id, it helps me determine to filter them accordingly.

As i may not be confident as how this should work, just a quick query. Anyone here would Kindly let me know if i can use the Location id on this matter? Big Thanks.