Say I create a book database (content type), which has an entity reference field to a separate author database (content type). I can now link all books to a specific record for their respective authors. Great.
But is there a way to automatically show all books linking in to the author record on the page for the author?
Comments
You can do that with Views, for example. Not sure how familiar you are with that core module.
Create a block with a contextual filter on the "author" node ID, and based on that relationship get the book node IDs. Put that block in the layout in use on "author" pages.
Thanks! I think I get the general idea.
I set up a block, which shows (at the moment) everyone’s books on the author page. I also found the contextual filter area in the view for this block. But that’s where it stops. I don’t know how to set up a filter which would dynamically limit the output of the books to the ones who have a (entity reference) link to the author currently being looked at.
I'll try my best - views based on entity reference can be a challenge.
Here's a screenshot:
The regular Filter criteria filter only on published nodes of type "author".
The base for magic happens on the right side.
The contextual filter just filters the current author, does nothing with books
The relationship connects the books. The title field - on the left side - uses this relationship to display book titles instead of author titles.
I hope, this gets you a step further.
There are a few ways to achieve the outcome, but it does depend on how you want the page displayed.
You can also use the Views module to create the Author page, select the author fields you want to display... similar to the above...
Then use the "Attach" to add a list of books below the Author details.
If you can provide more details, I'm sure we can help you build the page.
Another easy way to do this is to use the module Corresponding Entity References (cer). You would need to add an entity reference field in the authors content type pointing at the book, then set cer to create reciprocal references automatically. When you edit a book and select an author, cer will automatically set the back reference.
I don't think there is currently a way to set back references in bulk for existing books that already reference an author - you may need to do manually.