This module provides a default view, "My bookmarks". But it might be that you want to allow users to see other users' bookmarks.

If you want to setup a "user/%/bookmarks" tab on each user's profile page, these instructions are for you:

  1. Start a new view. (Make it a node-type view if you're flagging nodes; a user-type view if you're flagging users, etc.)
  2. As usual, pick a name, and possibly a description, for your view.
  3. Add a Page display.
  4. You may wish to style your view as a Table. Add the Node: Title field.
  5. Our tab needs a URL. Type user/%/bookmarks in the Path setting (You can replace the "bookmarks" word with whatever you wish).
  6. In the Menu setting choose "Menu tab" and type a short label into the Title
  7. Add the desired "Flags: Node flag" relationship (if you're flagging users, or comment, adjust accordingly). In this relationship settings form, choose by "Any user" to show all the flagged nodes (we'll filter them when we add the Argument).
  8. Add the "Flags: User" relationship.
  9. Add the "User: Uid" argument. In its "Relationship:" dropdown pick the "Flag user" relationship.
  10. You may want to type Bookmarks for %1 into the argument's Title box.

You're done.

Some refinements:

  1. You may want to type "This user hasn't bookmarked anything." into the Empty Text box.
  2. You may want to add the "Flags: Flagged time" field and let the user click-sort the table by it as well.

Comments

garbo’s picture

Hi, This is a nice feature for users but the problem is that it's not safe! Any user can now see the flagged content by any other user simply by filling in the correct UID.

To make sure users can't see each others bookmarks (or e.g. products in wishlist) do the following:
- add a second argument: User ID
- set the relation for this argument to "Flag user"
- set as "Action to take if argument is not present:" "Provide default argument". Argument type: "User ID from logged in User"
- Set as validator "Custom PHP code"
- add the following PHP:

 if($argument == arg(1)){
return TRUE;
} else {
return FALSE;
} 

This is checking whether the UID of the current user is matching the UID in the URL of the page!

kevinwalsh’s picture

I believe the intention of this page is to make a users' bookmarks public, similar to the list of a users' "Likes" on Facebook.

garbo’s picture

In that case it is indeed good as it is. In my case I'm using the flag module for costumers to create a personal wishlist of products in a webshop. This list needs to be private.

Anyway, now developers have the choice to create a private bookmarks list or a public one!

Michsk’s picture

How do you set that relationship. When i do exactly what is described in this handbook and then additionally add your code concept. I can not select an relationship when i set the second argument User ID. There is no relationships dropdown list.

mooffie’s picture

@garbo: I believe your little recipe is convoluted. To make only the current user's tab accessible, go to the existing "User: Uid" argument, and into a "PHP Code" validator type "return $argument == $GLOBALS['user']->uid;". It works for me.

(People, please help maintain this page: if you can validate that this indeed works, add this information to the HowTo and then ask the webmaster to delete all these comments.)

Michsk’s picture

I changed the howto without testing, since you stated it worked for you. But now im working with it and it doesnt work...

javdich’s picture

I had deleted the default "bookmarks" flag by accident and have been looking for a way to replace it using views.

I used the PHP code posted by mooffie. I also added Action to take if argument is not present: Hide view / Page not found (404). The tutorial works and i have tested it on my live site.

pragna’s picture

I have set the flag link on user-profile and give right to company1 role to flag any user.
Now I want to create tab and list of flagged users by current user.
I tried to create list using views but not getting success.

is that possible using views?

Pragna J Bhalsod

pragna’s picture

Hello all,

I have solved flagged users list using content profile module.

Thank you,

Pragna J Bhalsod

kpastore’s picture

To make this a step by step for Drupal 6.x version, once editing the view, do the following:

1. Click on the argument "(bookmarks_user) User: Uid"
2. Change validator option to "PHP code"
3. Enter return $argument == $GLOBALS['user']->uid; into the code area
4. Click "update"
5. Click "save"

gtothab’s picture

@garbo Hey thanks that worked like a charm for me.

geerlingguy’s picture

The process is somewhat similar for Views 3.x / Flag for Drupal 7:

  1. Add the 'Flags: [flag type]' relationship, and set 'By' to 'Any user.'
  2. Add the 'Flags: User' relationship; don't set any options for it.
  3. Add the 'User: Uid' contextual filter, and set it to 'Provide default value' 'User ID from URL'.

See: #1191228: Display Nodes Flagged by a Given User (rather than current user) in a View.

__________________
Personal site: www.jeffgeerling.com

aliceduck’s picture

Is there something you do differently in the menu tab section for Drupal 7/ Views 3 too?

drnikki’s picture

Thanks for this. It totally works, but I just want to emphasize how important it is to set the relationship in the contextual filter (and how easy it is to miss!!) I lost a few minutes trying to figure out why this didn't work when all I had to do was set the relationship.
https://skitch.com/drnikki/ggw1g/flagging-user

aliceduck’s picture

How do you create the menu tab with views 3?

The page settings -> menu has changed since views 2. I clicked default menu tab -> menu tab (under parent menu item), but the new tab still doesn't appear on the user profile page.

Can someone please help?

picxelplay’s picture

Make sure your view page path is: /user/%/bookmarks
Type: Menu Tab
Title: Something like 'My Bookmarks'
Make sure 'Context' is un-ticked

----
Sudo Kill Cylons

matthieuscarset’s picture

The Bookmarks module is now updated to work on Drupal 8+ and it provides a tab for each User to view their list of favorites: https://www.drupal.org/project/bookmarks