When dealing with non-global (per-user) flags, it would be really useful to reset flags per-user. Won't break any custom code, and I could really use it.

Also, unrelated to the patch, I was really confused by that module_invoke_all() line. What does $rows have to do with anything? And wouldn't the call be module_invoke_all('reset_flag')?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett’s picture

Oh, I just realized the point of $rows. So maybe that line change would mess up any custom implementations. I'll leave as CNR, but I could use some insight on that part.

jeff.k’s picture

+1 subscribing

Shadlington’s picture

Subscribing

westie’s picture

Would be a great feature, we use flags to mark content as read, however when important changes are made to the content we want to reset the flags and force users to read it again.

BigMike’s picture

Subscribed

MacaroniDuck’s picture

Yes, please.

code-brighton’s picture

Version: 6.x-2.x-dev » 7.x-2.0-beta6
FileSize
1.13 KB

I've created this little module to reset all the flags for the current user (using session if not logged in). It could probably do with a bit of tidying up, but I thought I would upload it as it might prove useful for someone. This is for Drupal 7.

To add your link to your theme file:

<?php print(flag_reset_link('Clear flags')); ?>

code-brighton’s picture

FileSize
1.13 KB

oops the line

$items['flags/remove/user/%user'] = array(

should have been:

$items['flags/remove/uid/%user'] = array(

updated file attached

joachim’s picture

Status: Needs review » Needs work
+++ flag.module	7 Oct 2010 19:17:08 -0000
@@ -929,15 +929,15 @@ function flag_trim_flag($flag, $account,
-  module_invoke_all('flag_reset', $flag, $content_id, $rows);
+  module_invoke_all('flag_reset', $flag, $content_id, $uid, $rows);

It's changing the signature of hook_flag_reset()... which admittedly is undocumented. And we're in beta still.

Needs more pondering. Does anyone care to check whether our ecosystem modules make use of this hook?

warmth’s picture

Any news?

joachim’s picture

Version: 7.x-2.0-beta6 » 7.x-3.x-dev

> It's changing the signature of hook_flag_reset()... which admittedly is undocumented. And we're in beta still.

Bumping the version to 3.x, which is still in alpha, so we can change the hook signature without any problem.

(Though bear in mind that I hope to have a beta out in the next couple of months -- so if this patch is to get in for 3.x, we need someone to step up and work on it!)

alexweber’s picture

I've taken a look at the latest dev branches for the following modules:

  • Flag Weights
  • Flag Friend
  • Flag Files
  • Flag Abuse
  • DLike
  • Conditional Flags
  • Flag Service

These are the ones listed on the project page and documentation pages and NONE of them have a single mention of "hook_flag_reset", therefore my understanding is that this is safe to implement.

Where's that re-rolled patch now? :)

RAFA3L’s picture

Thanks code-brighton, the #9 work perfect, but using the name flag_reset damage all the flag links, error 500 in a popup window after flag or unflag click. changing the name of the module to flag_flush work fine.

joachim’s picture

> using the name flag_reset damage all the flag links, error 500 in a popup window after flag

What was the text of the error?

RAFA3L’s picture

page not found error 500 + the url of the link to flag and unflag, for example...

http://localhost/test/flag/flag/bookmarks/1?destination=node&token=chW1Q...

joachim’s picture

Any log messages?

RAFA3L’s picture

No, before rename the module and the error appear I opened the Terminal to check the logs with tail -f and did nothing.

I'll try this again today with "flag_reset"

RAFA3L’s picture

Finally today I did a test, installing Flag Reset I get this when flag something and after rename the module to Flag Flush the error disappear.

Notice: Trying to get property of non-object en flag_reset_flag() (line 1272 of /Applications/MAMP/htdocs/test/sites/all/modules/flag/flag.module).
Recoverable fatal error: Object of class flag_node could not be converted to string en DatabaseStatementBase->execute() (line 2139 of /Applications/MAMP/htdocs/test/includes/database/database.inc).

joachim’s picture

> Notice: Trying to get property of non-object en flag_reset_flag() (line 1272 of /Applications/MAMP/htdocs/test/sites/all/modules/flag/flag.module).

That looks nothing like my numbers. Can you use the latest from git, or tell me what is on that line?

BTW, there is this project: http://drupal.org/project/flag_clear which is abandoned, but the name could be taken over. There's also code at https://github.com/mooffie/flag_clear which could be worth looking at.

Stan.Ezersky’s picture

using the name flag_reset damage all the flag links, error 500 in a popup window after flag

Rename module and you'll be glad-)