2

I have a Paragraph with an Entity Reference Field "link". This Paragraph belongs to Content Type B.

I want to create a reverse Entity Reference for "Link": all nodes that have the paragraph with this Entity Reference should be listed.

I tried

  • content_dependency - does not seem to work with Entity References within Paragraphs
  • reverse_node_reference - not working at all?
  • Custom View: did work with a entity reference without a paragraph (relationship referencing ER field) but not with the paragraph....

Any ideas?

0

2 Answers 2

3

After many days of unraveling views, entity references, and paragraphs, I finally figured this out. The moment was celebrated with an awkward, club-footed jig.

For context, I'm building a financial data delivery site that connects investment fund managers with funds to manage. My content types look like this:

I have an entity type called Contact, which has inside it a Paragraph field called Job History. There are 3 different job history paragraph bundles for 3 different types of jobs, but each type has fields for Job Title, Phone, Email, Employment Date, and an entity reference field called Fund. I also have another entity type called Fund, which is referenced by the Fund reference field.

1. Contact (entity)
- Job History (paragraph)
-- Fund
-- Job Title
-- Phone
-- Email
-- Employment Date

2. Fund (entity)
- Various fields (irrelevant to this solution)

I want to create a table view that will appear on all Fund pages, and show any contacts, with their contact info, for said Fund. In other words, this view should display any Contact nodes that reference the current Fund node, along with those nodes' phone, email, etc fields. I can achieve this using only Views...

  1. Create a content view and filter by node type: Contact.
  2. Add a relationship, Content: Field (Job History). This allows me to access the fields inside the Job History paragraph field.
  3. Add all above fields I want to display (name (title), job title, phone, & email) to the Fields section, making sure each one uses the Paragraph item from field_job_history relationship.

At this point, I have a view that displays all contact nodes & their fields. Let's narrow it down to those that reference only the current Fund node.

  1. Add a relationship, Entity Reference: Referenced Entity (A bridge to the Content entity that is referenced via field_reference_fund). Use the existing relationship, Paragraph item from field_job_history.
  2. Add a contextual filter for Content: NID. Use relationship, Content entity referenced from field_reference_fund. Provide default value: Content ID from URL.

The view will now display the fields within the paragraph, and limit the results to only those nodes that reference the current node.

I hope this provides the solution you were looking for!

1

This is what I get of your question. There is an Entity reference field.say Node with ID=1 points to nodes 3 and 4 but nodes 8,9,5,6 points to 1. So by filtering the 1 you need to get 8,9,5,6 not 3,4 .

1 ---> 2

1 ---> 3

5 --> 1

6 --> 1

8 --> 1

9 --> 1

after entering 1 5,6,8,9 must be listed.

By this assumption This is the solution. No module is needed. Just create a View of Content type B and check the

Entity Reference Field

A bridge to the Content entity that is referencing Content via field_reference

and Save. Make sure you have not selected the A bridge to the Content entity that is referenced via field_reference you must select A bridge to the Content entity that is referencing Content via field_reference as Relationships. To see what contents are pointed from Content type B, Create a contextual filter of nids. This node ID will be the node IDs of content type B (it's role equals to 1 in above example). Click on it and select the relationship. like this

enter image description here

Select Title as Fields and now by entering any input as node ID of content type B the contents that are related to this node are listed.

If you are using URL alias you can simply use this method in hook_preprocess_node get the node ID and use views_embed_view() function and passing the node ID as parameter to get this view's result.

5
  • your assumption is correct, so far. But my problem is the paragraph item - to get the entity reference field I need to add a relationship: "content paragraph" first. Only afterwards I can add the entity reference field "liink" as a relation (like ypu said), but since it is within a paragraph it is not the same. Is says bridge to the Paragraphs item entity that is referencing Content via field_paragraph_reference - and not bridge to the content entity ...
    – scar
    Commented Jul 7, 2015 at 14:18
  • What is the paragraph? Your content type machine name?
    – M a m a D
    Commented Jul 7, 2015 at 14:26
  • There is no need to add entity reference field. Just do what I said and add title or any other field it will work. I tested this solution and I got the relevant field values
    – M a m a D
    Commented Jul 7, 2015 at 14:28
  • A module called paragraphs (drupal.org/project/paragraphs), that provides its own entity bundles (kind of like field collection)
    – scar
    Commented Jul 7, 2015 at 14:34
  • I know nothing about this module. Anyway, This is a general solution and a few modification may end this to work
    – M a m a D
    Commented Jul 7, 2015 at 15:13

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.