Drupal - View for Entity Reference reverse, backwards forwards

  • 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.

Tags:

Entities

Views

8