In Drupal 7, using Flags (and possibly Rules or another contrib module) how can I force a flag to be unique for a specific content type. I do not want to force users to manually 'unflag' content before 'flagging' a new node. I would like reviously flagged nodes to be automatically unflagged once a new flag has been set.

The goal is to allow users to select a 'default node' by use of flags. Only one default node should be allowed.

How can I force and automate flag uniqueness?

2 Answers 2


Drupal Rules has a Trim-A-Flag action that lets you set a 'queue' size, or a 'max' number of flags allowed. If you set the queue to 1, you can force a flag to be unique, and have it automatically update when a new entity is flagged.

Screenshot below.

Drupal Rules Trim-a-Flag settings


You could use hook_flag($action, $flag, $content_id, $account) to do this. In this hook, check for content type, and then unflag all unneeded nodes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.