This video will teach you how to create a block with Views that lists content that has been favorited by a user. We will create one block, that will show the appropriate content based on the user profile that is being viewed.

  • Go to "Structure => Views => Add new view" (admin/structure/views/add)
    • View Name: Favorites
    • Uncheck "Create a page" (We won't need a page, because we are going to use a block)
    • Check "Create a block"
      • Display format: HTML list of titles(linked)
      • Items per page: 10
      • Check "Use a pager"
  • (Continue & edit)
  • Advanced
    • Click "Advanced"
    • Relationships: Click "Add"
      • Select
        • "Flags: Node flag"
    • (Apply (all displays))
    • Configure Relationship: Flags
      • Identifier: flag
      • Select "Include only flagged content"
      • Flag: Select "Favorites"
      • By: Any user
    • (Apply (all displays))
    • Contextual Filters: Click “Add”
    • Select:
      • “Flags: User uid”
      • (Apply (all displays))
    • When the filter value is not available
      • Choose “Provide default value”
      • Type: User ID from URL (We’re going to display the block on user profile pages. So this will get the User ID from the profile that we are viewing. It also ensures that it will only show on user profiles, and not on any other page.)
      • (Apply (all displays))
    • No results behavior
      • No results behavior: Click "Add"
      • Select "Global: Text area"
    • (Apply (all displays))
      • Label (Textarea): This user has not yet favorited any content.
    • (Apply (all displays))
  • (Save)

Next, we are going to display the block in the right sidebar

  • Go to "Structure => Blocks" (admin/structure/blocks)
    • Scroll down to "View: Favorites"
    • Click the dropdown for region and choose "Sidebar second"
  • (Save blocks)

Go to home, and the Favorites block is not displayed, but if we go to my user profile page, we see the block. Now, I’ll favorite an article to see if it works.

Go home and click "Add to favorites". Now, when I go to my user profile, we’ll see the article is in the Favorites block.

If we go to another user’s profile we’ll see that they have not favorited any content, so everything is working!

Now, let’s create a view that shows the most favorited content site-wide.