0

I am really confused about this. Tried with the Entity reference view but can not get the result working for me. It should be very easy to do it.

I have a node called Book. Book has a field field_author that is referenced to USER.

I am trying to show the related books by the same referenced user.

Book 1:

Title: Book 1
field_author: user50 //id of this user is 50

Book 2:

Title: Book 2
field_author: user15

Book 3:

Title: Book 3
field_author: user50

Book 4:

Title: Book 4
field_author: user50

My view should display Book 3 and Book 4 when viewing Book 1 (URL:: example.com/node/1) and display Book 1 and Book 4 when viewing Book 3 (URL:: ecample.com/node/3) and so forth.

1 Answer 1

0

What you want to do is often called displaying sibling items. In your case the connection is the ER user connection (not Taxonomy) but you can find examples with details about how to do it, search answers for it.

In short:

  1. Create Views of type Book, you'll probably want Block Display, it doesn't have to be Entity reference Display type (that is for influencing choices in nodes in ER fields).
  2. Add the Relationship for the User ER field. It should be the forwards Relationship. You can require it if you want to exclude all Books from your list that don't have the User ER filled in.
  3. Add the second Relationship for that field, but the reverse one this time (it will be called different). Make it use the first Relationship. You can require it.
  4. Add Contextual filter for Node ID, make it use the second Relationship (because this way you get the ID of sibling nodes) and configure it the usual way (default value ID from URL, validate Book node type) etc.
  5. The current Book node will also be listed. To exclude it add another Contextual filter for node ID, don't make it use any Relationships, set to default value ID from URL and under "More" choose "Exclude".
  6. Under Structure > Blocks set the Block to display in a theme region, and configure it to use Contextual options. Don't forget the Visibility settings too.

You should now see the block on Book nodes showing their siblings per shared user ER.

You can test Contextual filter when editing Views by entering values into the Preview field. If you have two Contextual filters you have to enter two values separated by "/" In your case enter a book node twice e.g. "12/12". "all/all" usually bypasses the Contextual filter results.
You still have to check that it works by placing the Block in a region at the end, to check your Contextual configuration is correct.

Your Answer

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

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