Favorite documentation pages
As site member, I would like to mark documentation pages as favorites. A list of marked pages should appear as a tab on my user page, and the five most recently added should also appear as a block in the sidebar. This is important since it helps me access content I find useful.
- Log in to the site.
- Flag at least six documentation pages as favorites. (Create the pages first, if necessary.)
- Verify that the five most recently added are visible in a sidebar block, linking to the respective documentation pages.
- Verify that the block links to a page listing all six documentation pages, with links to the respective pages. Verify that this page appears as a tab at the acting user’s profile page.
- The site should have a documentation page content type, as provided by the first exercise in this suite.
- As with the previous exercise, this could be implemented as a tab found at each user page, or only on your own user page – the latter task being drastically simplified using Page manager (and an access rule to compare acting user with the user for whom to list favorites).
- When building the block display, it is possible to use the flag relation option to include content flagged by current user only. However, this would make it difficult to use the more link – since the page display expects a contextual filter value. A better, but somewhat more heavy approach (for Views), is to use the same contextual filter settings but allow the block to fetch a default value for the filter.
- Add a new node flag. Give it the name favorite and the title favorite documentation. (See configuring flags in chapter 11.)
- Give the flag descriptive flag/unflag link texts, descriptions and confirmation messages. Allow all authenticated users to use the flag, and allow flags to be put on documentation pages only. (See configuring flags.)
- Add a new view. Give it the name favorites, and have it list content without any specified sort criteria. Create a page with the path user/%/favorites, displaying 10 teasers at a time, with a pager. Also create a block, showing five linked titles without any pager. (See creating new views in the Views basics chapter.)
- In View's main configuration panel, add a new relationship flags: node flag to get information about all the flags on the listed nodes. Use the favorite flag, and include only flagged content – but include content flagged by all users. (See combining Flag and Views in chapter 11.)
- Add another relationship, flags: user, to get information about the user setting each flag. (See combining Flag and Views.)
- Add a contextual filter user: uid, restricting the view to list only content where the flagging user has the user ID provided by the contextual filter value. If the filter value is missing – which will be the case for the block – provide default value from user ID from logged in user. Also validate that the filter argument is a user ID. (See configuring contextual filters in the advanced Views configuration chapter.)
- Add a sort criteria flags: flagged time, for sorting the list with newest flaggings on top. (See data fields from flags in chapter 11.)
- In the block display, override the contextual filter settings. Set the title to your recent favorites. Also override the more link option (in the middle column), setting it to yes. (See overridden configuration in the Views basics chapter.)
- Give the block the block name active user's favorites. Save the view. In the blocks administration page, place the new block in one of the sidebars.