The need is to present in a landing page a view of all pages that do reference to this landing page. So, this view will search in other content type, to find in a reference field that contain same id.

Landing page content type have several nodes children.

Page content type have a Entity reference field_back_parent for a node parent

Content types Landing page (1) parent, Page (2) child, Page (3) child,

I would like to this using UI in admin. So, no entityQuery in this opportunity.

  • You can also use a module instead of (or instead of only) core views: drupal.org/project/reverse_entity_reference > Reverse Entity Reference adds a computed reverse reference field to all referenced entities.
    – mlncn
    Commented Sep 30, 2019 at 9:50
  • Nice comprehensive answer below from Carlos (I haven't tried it myself yet though). What I have tried and found to work is: drupal.stackexchange.com/a/298084/1082 (albeit a programmatic solution, but if one is already doing coding for their project, then this other answer is simple solution that I have tried). Commented Mar 7, 2022 at 0:40

1 Answer 1

  • No additional module need to be installed.
  • No coding needed. Just site building for Drupal 8.
  • First we need to check if our content types are ready.

Landing page content type, don't need any change. Page content type need a field of type Entity reference.

  • Add field -> Add a new field = Reference Content

Then in Edit tab chose your kind of content type (parent)

enter image description here

After Save you will get...

enter image description here

Now go to admin/structure/views and + Add view

enter image description here

In this case we are going to check the option to create a block

enter image description here

In ADVANCED enter image description here

Add Relationship for our field_back_parent in Page content type. This important to connect the two content types.

enter image description here

You need to tick Require this relationship.

enter image description here

In ADVANCED enter image description here

Then Add Contextual filter for our current content type Landing Page. In this way, we will get our actual node id to be used in the view. So, now we can find only the pages that have same node id in field_back_parent.

So find by ID (Content)

enter image description here

Select the relationship name.

Check Provide default value -> Content ID from URL

enter image description here

Then you will get something like this:

enter image description here

In Relationship you must to have the word Content in the rightside

This is the result of our settings enter image description here

If you click in Update preview you will corroborate that it doesn't display anything.

You must to add the node id from parent. In our case is the node 2 from Landing page. enter image description here

Other way for reference https://mushtaqtahir.com/blog/4/drupal-8-reverse-entity-reference-in-view

I hope that this info help you.

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.