List user's content on a user page tab
As site member, I would like to have a list of all the content I’ve written available as a tab on my user page. I would like similar tabs on other users’ pages. This is important since it helps me keep track of my own contributions as well as following what other members write.
- Log in to the site.
- Create a documentation page.
- Visit the user account page and click on the tab “Posts”. Verify that the documentation page is listed.
- Create a documentation collection.
- Verify that the documentation collection is listed, too, and (since it is newer) is listed above the documentation page.
- The site should have the documentation page and collection content types, as provided by the first exercise in this suite.
- You may or may not have to add the relationship in step 3 in the suggested solution – it depends on how the Views module is changed the next few weeks. (Normally, content authors are automatically available in a view of nodes, but this may change.)
- Whenever you have a view using contextual filters, you should have the view returning page not found if contextual filter value is missing – unless you have reasons to do otherwise. This prevents the view from being used in unexpected contexts.
- The user story doesn't say how the content should be displayed. A teaser list is easy to make and usually pleasant to look at – changing it to a table, for example, can be made in a future user story if the client would like to change the appearance of the list.
- Add a new view with the name content by user. Have it display content of all types, sorted with newest on top. Create a page with the path user/%/posts, with a list of 10 teasers per page, and no menu link. (See create new views in the Views basics chapter.)
- In the main configuration panel, add a menu item of the type menu tab and give it the link text posts. (See creating menu tabs in advanced Views configuration chapter.)
- If the contextual filter user: uid is not present, add a new relationship content: author. (See adding relationships in chapter 9.)
- Add a new contextual filter user: uid. Use the title override option to set the title to content written by %1. Use the validation options to verify that the contextual filter value is a user ID. (See configuring contextual filters in chapter 9.)