Using Drupal 7, Views and Entity API I am trying to create a View which shows the logged in User all downloads which are available to him.
I use the following Content Types:
- Software
- Software Pack
The User has an entity reference field that accepts 1 value to reference a Software Pack. user_software_pack
The Software Packs include an entity reference field that accepts unlimited values to reference Software included in the Pack. field_included_software
For the View I am creating an unformated list of Content Teasers of Type Software
Doing this shows me all Software that is published, I am now attempting to filter the list to only the Software available to the User using the following relationships.
- A bridge to the User entity that is referencing Content via field_software_pack
- A bridge to the Content entity that is referenced via field_software_pack
- A bridge to the Content entity that is referenced via field_included_software
To me this would translate getting the user, then using that to reference the Software Pack to then reference the Software in that Pack. The view shows me all Software entities. Am I missing something?
Setting the Show: Content settings to use the relationship gives me an empty view, setting a relationship as required provides an empty view as well.
After taking a lengthy break and coming back to the problem I managed to solve it.
For anyone who might get stuck on a similar problem: I was using one relationship too much.
My view shows al content of type Software. Software is referenced in multiple Software Packs (field_included_software) and the User profile has a reference field (field_software_pack) to 1 Software Pack.
To filter the view of content type Software it requires first setting up a relationship to the Software Packs that are referencing Software.
Then it needs another relationship to the User Profile referencing which Software Pack the user has.
To get the User ID of the logged in user to limit the results to only the Software in the Software Pack of the user a contextual filter is needed.
The contextual filter is set to provide a default value from PHP Code:
Relationship for the contextual filter is set to the User reference.
All relationships have to be set as REQUIRED.
Once I configured my view like this everything worked as planned.