2

Suppose I have a content type (Song) which has a content reference field, referencing an Album node to which it belongs. When I view an album, I want to show a list of all songs which reference that album.
Can this be done?

I'd rather not use a taxonomy term. I've looked at the "Manage Display" screen for the Album content type, but I could not find any way to display the songs which reference it. I know that I can create a view which filters by album, but I want to display this information directly on the Album view screen, so when users click the album link, a list of all songs on that album will show up. Is this possible?

  • 4
    This can be done with Views (part of Drupal 8) and EVA: Entity Views Attachments The tutorial on the EVA page does something very similar. You can use your entity relation to relate the songs and albums within views. – Neograph734 Mar 4 '17 at 20:43
  • No problem, nice self-answer. :) – Neograph734 Mar 7 '17 at 6:21
2

Thanks for this comment pointing me to the EVA module. Here are the exact steps I had to take in Drupal 8, which is slightly different than Drupal 7.

Steps for Drupal 8:

  1. Make sure your reference field is already set up (e.g., the Song entity has a field referencing an Album)
  2. Install and activate the EVA module
  3. Add a new view (Manage > Structure > Views > Add View)
  4. Type in the view name, and in View Settings, set it to show Content of type Recording (i.e., the "child" entity). No need to "Create a page" or "Create a block".
  5. Under the Displays heading will be a label called Master. Click the Add button just to the right of that.
  6. Select "EVA", not "Entity Reference" (this is a difference from Drupal 7)
  7. Under Displays > Format, I like to change "Unformatted list" to "Table".
  8. Under Display > Entity Content Settings, change "Entity type" from "None" to "Content".
  9. Change "Bundles" from "All" to "Album" (i.e., the "parent" entity)
  10. Under Advanced, add a "Contextual filter".
  11. Search for the field which links Recording to Album (i.e., the field in the child entity which references the parent), and select it, and click "Add and configure contextual filters".
  12. Under "When the filter value is not available", select "Provide default value" and choose "Content ID from URL".
  13. click "Apply".
  14. If you know the ID of an album (parent entity), you can enter it in the parameter in the "Preview" section to make sure it is working as expected (you will need to pre-populate entities to test this).
  15. Click "Save" under the "Display" section for the view.
  16. A message should show up: "The view ___ has been saved."
  17. Clear all caches (Manage > Configuration > Development > Performance > Clear Cache > Clear All Caches).
  18. Navigate to a sample parent entity, and the child entities should show up on that page.
0

You can create the views list as you suggested and use the viewsfield module to embed it in your content.

Your Answer

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

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