Display nodes (entities) created by a user on his profile page in Drupal 8

A very simple, traditional and I would say - classic example task we'll be tackling today - displaying nodes (entities), created by a user on his profile page.

First, make sure you have Views and Views UI modules enabled. Views are in core now, so no extra work is needed here.

Structure >> Views >> Add view

Under the View settings section select the entity type we'll be filtering by, and on the same page tell Views to create a Block display for us.

On the next screen (the Block display edit page) go to the Advanced >> Relationships section and hit the "Add" button to create a new relationship.

In the list which appears right after, filter items by a "User" category and select the Relationship: author. This relationship should be required, as we don't want items posted by other authors showing up on the user page.

Next, scroll up to the Contextual filters section and click the "Add" button to create a new contextual filter.

As before, filter items by a "User" category and select the "User ID" filter.

On its configuration screen make sure the filter uses the relationship we've created before and configure the rest of settings like so:

When the filter value is NOT available >> Provide default value: User ID from route context

That's it for now. Stay tuned for more Drupal 8 related stuff!

Igor Kandyba's Image
Igor Kandyba
Minsk, Belarus

I'm building Drop Guard - the ultimate continuous security solution for Drupal