0

I am using Drupal 8 in combination with the Forum module, and I'd like to show all comments and nodes by a user on his profile page, in a single view.

I can't find a way to get this to work, because they are different entity types.

I've tried using two relationships, but that only gives me rows with each comment linked to each node.

Is this at all possible?

EDIT: This is an example of the result that I'm trying to achieve:

  • Comment 5
  • Comment 4
  • Node 2
  • Comment 3
  • Node 1
  • Comment 2
  • Comment 1
2
  • 1
    Create a new view mode for that. Add node field and comment in that view mode . Then create a new view and select that view mode . Also you need to add contextual filter for node author uid. Sep 28 '18 at 5:29
  • @PankajYogi I don't think that's what I'm looking for, I've updated my question to be more specific on what I want to achieve.
    – RobinAOC
    Sep 28 '18 at 10:58
0

This is an example of my setup, just switch out article or content type for your content type or forum posts.

node--article--teaser.html.twig:

<div class="{{ node.type.0.target_id | clean_class }}-teaser-wrapper" {{ attributes }}>

    {# other fields #}

    {{ content.field_comments }}

</div>

or:

<div class="{{ node.type.0.target_id | clean_class }}-teaser-wrapper" {{ attributes }}>

    {{ content }}

</div>

As long as the comment field is set to display in your teaser view mode, and printed via your template, the comments will show in the view results.

View Config:

enter image description here

The contextual filter is the important part.

enter image description here

enter image description here

This setup uses content format teaser, the alternative would be using fields. Both will work, with fields you may need a relationship to comments depending on what fields you need available in your view.

1
  • doesn't this show all content by a user, including all comments to that content? Because I am trying to display only content by a user, whether it's comments or nodes, in the same view.
    – RobinAOC
    Sep 28 '18 at 20:13

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.