When using the Trim Flag rule there is only one option that exists, to trim the oldest flag based on the flagged order. Since I'm using Flag Weight and Views so that users can organize their flagged nodes by custom order, I would like to be able to automatically trim the flag with the greatest flag weight. Also it would be nice to see an option to trim the newest flag in order to prevent new flags once a limit is reached.

Files: 
CommentFileSizeAuthor
#5 flag-feature_trim_newest-1988258-5.patch2.86 KBShabana Blackborder
PASSED: [[SimpleTest]]: [MySQL] 266 pass(es).
[ View ]
#2 flag-feature_trim_newest-1988258-2.patch2.85 KBShabana Blackborder
PASSED: [[SimpleTest]]: [MySQL] 266 pass(es).
[ View ]

Comments

The Rules integration is currently unmaintained, so this issue is entirely dependent on users of Rules providing a patch.

Status:Active» Needs review
StatusFileSize
new2.85 KB
PASSED: [[SimpleTest]]: [MySQL] 266 pass(es).
[ View ]

> Also it would be nice to see an option to trim the newest flag in order to prevent new flags once a limit is reached.

The attached patch takes care of this. As for trimming flags with the greatest weight, ASFAIK, the flag_weights module does not have a stable version that integrates with the newest version of the flag module. Consequently, I think that can wait until the maintainers for that module releases a stable version.

Status:Needs review» Needs work

Thanks for working on this.

Here's a quick eyeball review:

+++ b/flag.module
@@ -2066,16 +2066,28 @@ function flag_create_link($flag_name, $entity_id) {
+ * @param $trim_newest
+ *   A boolean indicating whether to trim the newest flags.

If we're adding to an API function on our stable branch, we should make this param optional and default to the existing behaviour.

+++ b/flag.module
@@ -2066,16 +2066,28 @@ function flag_create_link($flag_name, $entity_id) {
+    ->condition('sid', flag_get_sid($account->uid));
+    ¶
+  // If $trim_newest is TRUE, then, we should order by 'ASC' as we should trim the newest flags

Remember to trim whitespace :) Your text editor should have a command to do this automatically.

Also, wrap comments to 80 chars and finish sentences with a .

+++ b/flag.rules.inc
@@ -186,6 +186,11 @@ function flag_rules_action_info() {
+        'trim_newest' => array(
+          'type' => 'boolean',
+          'label' => t('Trim newest flags'),
+          'description' => t('Checking this will trim the newest flags.  This will prevent new flags once a limit is reached.'),
+        ),

How is the addition of a param going to affect existing rules? (Could users of Rules try this out please?)
Is there a way to declare this as optional?

Joachim, will update with the edits.

>Is there a way to declare this as optional?

Actually, this is an optional field. It shows up as a checkbox and is unchecked by default. So, it won't affect the existing rules until the checkbox is checked. And once it is checked, it will just trim the newest flags.

So, basically, it behaves like an option field and defaults to the existing behavior of rules.

Status:Needs work» Needs review
StatusFileSize
new2.86 KB
PASSED: [[SimpleTest]]: [MySQL] 266 pass(es).
[ View ]

The updated patch is attached. Let me know if I have missed anything. Thanks.

Status:Needs review» Fixed

Committed to 7.x-3.x branch.

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.