4

Using an Entityreference field in a content type A makes it possible to reference multiple items from another content type B to it. On node teaser pages or any other Views lists you can list them additionally on each row of content item from the content type A as a sub-list of referenced items. But how can I list the reference sources the other way around automatically without using another Entityreference field on the content type B (needless double-edit)?

Example: A car (content type A) has been repaired in 3 different car service stations (content type B). So the content type "car" gets a Entityreference field to add them (items from B). When I build a list of service stations (B), I would like to see a list of the cars (A) being repared in them automatically without an additional back reference field or additional modules like CER, making things needlessly complicated in the database.

enter image description here

NOTE: Basically it's the behaviour we would expect from Taxonomy terms, which are also Entityreferences in Drupal 8, but they seem to have some more build in functionality to work from both sides in item lists.

  • 4
    This is part of a long-term UX debate regarding the visual and conceptual understanding and meaning of referencesi and relations in Drupal content items. This is why we had references and relations module in contrib of D7. IMHO, I think the expected functionality in question you are asking for should be available. There is a possible work-around using Views relationchips but I don't know how this could be achieved, and if it has any flaws. – diqidoq Oct 11 '17 at 11:40
  • 3
    This example sadly only shows a solution for a single item view with a contextual filter drupal.org/node/2897448, which is easy to achieve, as you may know already. But how to solve your question in a node list with sub-lists, IDK atm. – diqidoq Oct 11 '17 at 12:43
  • 3
    Thanks for giving some ideas. I was wondering if I am completely mistaken with my approaches. – nilsun Oct 11 '17 at 16:21
4

At the moment I only see 2 (edit: 3) options to solve the backreferencing issue without creating SQL request duplicates:

  1. Using Views Field View for nesting a list of type A nodes referencing node type B via contextual filters in the second view to filter for each items nid (possible performance issue).
  2. Syncing 2 Entityreference fields from both content types and maybe automate them with Rules and using the second Entityreference field for the back reference list in Views.
  3. Using the CER module (I know you said no but), I think after testing that this module is the best option at the moment if you know that you want this connection synced "fix" and not individually changed.

First would have a huge performance impact if the lists and nested lists are long. And the caching modules required to compensate it are not ready yet for D8.

Second can have other issues sinces Rules not always work flawlessly and I am not 100% sure if Rules supports the needed triggers for this approach.

EDIT: Third is my recommendation. After testing around I was quite impressed about its simpleness and working warranty. It's not as flexible as using rules, but as I sad, rules is a story of ots own. So maybe you give it another try (CER).

  • 3
    Thank you for providing this useful work-arounds. It reads like smart solutions for it but I wonder: do you mean, there is no "out-of-the-box" way to list the referring sources in the list of referred items in Core? Isn't it strange? Or do I miss something in terms of flexibility here, why this is not possible OFTB? I voted up and will mark as solution if nothing more comes around. Thanks a million for your help! – nilsun Oct 11 '17 at 16:24
  • Tested CER again, like you recommended and you are right, it should be the way. Solution 1 is too dangerours and do not cover language settings. Solution 2 can be a little tricky if Rules do not work as expected. But all solutions are smart. So I marked your answer as THE solution. Thank you very much for your help on this! – nilsun Oct 13 '17 at 15:41

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.