Jan 15, 2016

Bookmarks using the Flag module in Drupal 7

The Flag module allows you to mark materials on the site, for example, to make lists with your favorites.

Flags are global and not global. The global flag is the only and unique material label. If one user has installed it, any other user will also see it and can remove it if he has rights to it. If the flag is not global, then the flags set by the user are individual — only he sees them.

It is the second option that fits the concept of bookmarks.

So let's figure out how to make them. Install the Flag module. 

Next, go to admin/structure/flags to create a flag. 

Click on the Add flag and select the type of entity that needs to be flagged with this flag. Choose Nodes and click Continue.

Below I just give a screenshot of the flag settings, everything is intuitively clear.

After adding a flag, you can try to create a node of type Article and check how the flag works.

Let's create a test Article. Once created, you will see a link to add the material to your bookmarks. Try to click several times and it works without a page refresh.

Create a few more materials and add some of them to the bookmarks to test the bookmark list.

To quickly create test nodes, you can use the Devel Generate module, which is included in Devel.

Turn on the modules and go to the  admin/config/development/generate/content address. For example, create there 50 articles.

Let's bookmark a few of the new articles.

Bookmark list

To create a list of materials that we have selected, we need the Views module.

Add a new view at  admin/structure/views/add:

I specifically created an address like user/%/my-bookmarks, to get the view into the user profile.

In the Advanced, you need to add a Relationship and mark Node flag, this will allow you to link materials to flags.

If the checkbox Include only flagged content is checked, the view will only show the materials marked with the flag, this is exactly what we need.

Choose which flag you want to link to. So far we have one, but there may be many.

The Current user selection is just right for non-global flags. Only the relationships that the current user has established will be considered.

Now let's make this output a tab on the user's page. In the Menu select the Menu tab and write the title of the tab.

Done! You can go to the user profile and see a tab with your bookmarks.