Drupal 8 Development Cookbook(Second Edition)
上QQ阅读APP看书,第一时间看更新

How to do it...

  1. 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.
  2. Set the View name to My Content.
  3. 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.

 

  1. 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.
  1. Toggle the Advanced portion of the form on the right-hand side of the page. Click on Add in the Contextual filters section.
  2. Select Authored by: Content and then click on Add and configure contextual filters.
  3. 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:
  1. Click on Apply and then click on Save to save the view.
  2. Go to /user/1/content, and you will see content created by the first user.