Back to top

Flags/Bookmarks configuration in Drupal 8

Flag module can be used to mark content, comments, users, taxonomy terms, entity forms, config entities, entity revisions and probably anything you can think of in Drupal. Its sophisticated interface and integration with Views and Rules are what makes it a perfect solution for so many different cases, way ahead of many other similar solutions.

Bookmark content–Flag module in Drupal 8

Configure your first Bookmark flag

All configuration for your Flags/Bookmarks is under Structure > Flags (/admin/structure/flags). This is where you create flags, set what entities to apply them to, choose which method to use for the flagging action, change the wording for various flagging-related actions:

Bookmark content–Flag module in Drupal 8

It's only if you choose to Display link as field will you see it listed on the Manage display settings for an entity type, and only to reorder it with regards to the other fields. You won't be able to edit any flag properties there like you do for other fields. This only controls the placement of the flag link on the entity page.

And only if you choose to Display checkbox on entity edit form will you see it listed on the Manage form display settings for an entity type. Again this only controls the order of the flag link in the entity Edit page.

List flagged content

The Flag module comes with Views that list the flagged content and another Views for favorited users. You can clone them and edit to suit your needs. Bookmarks Views are set to show only flags (Bookmarks) for the currently logged in user. If you need to create a page listing all flags, for example show a table of all Bookmarks for a node, you need to edit the Flags Relationship to pull in all users' flags:

Show all flags–Relationship configuration in Flags Views in Drupal 8

This Relationship also allows to show some useful information about the flags in question, like when they were bookmarked, and provides the links to add or remove the Bookmark.

Who flagged this?

To show which user flagged the content we need another Relationship: User from the Flagging category that will automatically be set to use the first Flags Relationship. This new Relationship introduces user info into the Views, which means we can add a Field User: Name and set it to use the User Relationship which means it will show the “owner” of the Bookmark (as opposed to the author of that content, for example).

How to list content Flags with Views in #Drupal8 @prkosTweet this

A Block with some of these settings can be placed on content pages, and with the help of the usual Content: ID Contextual filter it will list flags for that page only:

List Bookmarks on content page–Flag module in Drupal 8

Send notifications about Flags/Bookmarks

Rules module can be used to create various workflows around flagging on your site. For example, you can set Rules to send email notifications when something has been flagged. A message can be sent to admins, the user who flagged something, other users who want to know when new content gets flagged etc.

You can even design voting systems and similar features that utilize Flags to mark entities, and Rules to govern the circumstances and boundaries for the voting process.

Have you found any other interesting uses for Flags?

Need any help with this? Or with any other Drupal problem? Contact me for a friendly chat, share about your project and see how I can help you solve any issues you might have.