0

I have read many of the questions asked on this site, but none of them suited my problem. What is the need to make a Users view that shows below its created contents.

I have a website with 3 roles. Each role has the permission to create a content type. Users of the "Truckers" role can create nodes whose type is Trucks. The Username value is automatically added to a field, in order to identify which truck driver that truck belongs to. That field is an entity reference.

I need to create a view that shows users of the Truckers role and the trucks which belong to them. I created 2 views. One of them, based on the Trucks content type, lists the trucks, and among other fields, shows the Username of the truck driver who created it; the other one, based on Users, lists the users who have the Truckers role.

Using Views field view, I added the Trucks view as a field inside the Truckers view. However, I didn't find any combination of contextual filters, relationships, etc. that gives the desired result.

In the second image, you can see that the Trucks view is shown below each user of the Truckers role, but it shows all trucks, not just those created by the trucker.

List of trucks

Views field view in parent view

I am not a programmer. How could I achieve the result I need? Is there a contextual filter, relationship, that I need to set? They have many options and I do not understand all of them correctly and in depth.

I am using Drupal 8.9.13 and Views field view 8.x-1.0-beta3.

1 Answer 1

1

You should be able to accomplish this with one view. I don't think views field view is necessary.

Add a view that shows Users

In the Filter Criteria section filter it by role (trucker).

Under Advanced use the Relationships dropdown to add the relationship Content Authored.

In the Fields section add a field to show whatever field of the trucks content type you want to show for each trucker (e.g. truck name). You could also use title. This field setting will use the "node" relationship which is available as a result of adding Content Authored in the relationships dropdown in the advanced section.

If you do use title instead of something like truck name, or any field that appears in multiple content types, in the Filter Criteria section be sure to add a "content type" filter in order to restrict results to the trucks content type.

Format the results as you like (e.g. table, etc.).

1
  • 1
    Thanks, it works! Just a clarification: I only made it work by setting the output format as table, and grouping by a field, in this case Username.
    – Gery Mont
    Commented Apr 22, 2021 at 21:33

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.