Flags are usually used for marking content the user is interested in.

But sometimes the opposite is true: the user is flagging content she isn't interested in. For example, content she thinks is spam, offensive, or otherwise doesn't worth her time.

Another example: If the user is a moderator, she'd like to see content which isn't flagged, say, as "Reviewed", so she could review it.

For these cases we would like to show in our view only content which is not flagged. The "recipe" for doing this involves two steps:

  1. We start, as usual, by adding the flag relationship. The only difference is that now we uncheck the "Include only flagged content" checkbox. This will make our view list all content: whether flagged or not.
  2. We add the Flags: Flagged filter. We ask it to filter out flagged content. (In other words, in its settings form, under Status, we select Not flagged.)

Comments

Drupaled-1’s picture

This seems to be a an issue right now within views possibly?

How can we display lists of users who have not yet flagged a piece of content that has been flagged by others?

westie’s picture

This method seems to suffer from a huge performance problem, when unticking the "Include only flagged content" checkbox the view starts to crawl with a Query execute time of 8712.13 ms. With the box checked this takes only around 2-5ms...

I need to show content unflagged by specific users.

Is something on my install causing this problem or is filtering by all unflagged content that expensive in the database?

EDIT: Updated to Flag dev and the same query dropped to a under 10ms.

Tafa’s picture

Cool, thanks for the update. I am going through the same process at the minute on a localhost install and I did not experience that yet but always thought this might be an issue at some point.
T

Ayesh’s picture

Just look at the query.
Unticking the box didn't cause a performance problem according to query times. At least in my setup.

wardshark222’s picture

Great stuff, I implemented this on D7 and it worked out just fine. I wish I could display the flag link on a view listing comments though.

Pene’s picture

I think sometimes it is far easier to list all the flagged content by any user, and add a "Filter criteria" that looks for "Is empty (NULL)" User IDs (relationship: flag user is important).

nehapandya55’s picture

Thanks for this steps its help me alot.

alaa.ayyad’s picture

Not working with Drupal 9.1.2 unfortunately.

The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Drupal\views\Plugin\views\field\BulkForm::getEntityTranslation() must implement interface Drupal\Core\Entity\EntityInterface, null given, called in C:\xampp\htdocs\mysite\core\modules\views\src\Plugin\views\field\BulkForm.php on line 291 in Drupal\views\Plugin\views\field\BulkForm->getEntityTranslation() (line 69 of core\modules\views\src\Entity\Render\EntityTranslationRenderTrait.php).