- Drupal 8 Development Cookbook(Second Edition)
- Matt Glaman
- 231字
- 2025-04-04 18:20:51
How to do it...
- Go to Structure and then Views. This will bring you to the administrative overview of all the views created. Click on Add view to create a new view.
- Set the View name to My Content.
- Next, we will modify the View settings. We want to display Content of the type All and leave the Tagged with empty. This will allow all content to be displayed.
- Select Create a page. Keep the page title the same. We will need to change the path to user/%user/content. Click on Save and edit to move to the next screen and add the contextual filter.
When building a views page, adding a percent sign to the path identifies a route variable. By adding an entity type's name, Drupal will match the input as an identifier to an entity of that type.
- Toggle the Advanced portion of the form on the right-hand side of the page. Click on Add in the Contextual filters section.
- Select Authored by: Content and then click on Add and configure contextual filters.
- Change the default value of WHEN THE FILTER VALUE IS NOT IN THE URL to Display "Access Denied" to prevent all content from being displayed with a bad route value:

- Click on Apply and then click on Save to save the view.
- Go to /user/1/content, and you will see content created by the first user.