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.

How to Demo: 
  1. Log in to the site.
  2. Flag at least six documentation pages as favorites. (Create the pages first, if necessary.)
  3. Verify that the five most recently added are visible in a sidebar block, linking to the respective documentation pages.
  4. 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.
Required Preparations: 
  • The site should have a documentation page content type, as provided by the first exercise in this suite.
Additional Comments: 
  • 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.
Additional Resources: 
documentation_site_13.zip3.47 KB
Suggested Solution: 
  1. Add a new node flag. Give it the name favorite and the title favorite documentation. (See configuring flags in chapter 11.)
  2. 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.)
  3. 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.)
  4. 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.)
  5. Add another relationship, flags: user, to get information about the user setting each flag. (See combining Flag and Views.)
  6. 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.)
  7. Add a sort criteria flags: flagged time, for sorting the list with newest flaggings on top. (See data fields from flags in chapter 11.)
  8. 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.)
  9. 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.
Solution Video: