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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim’s picture

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

shabana.navas’s picture

Status: Active » Needs review
FileSize
2.85 KB

> 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.

joachim’s picture

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?

shabana.navas’s picture

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.

shabana.navas’s picture

Status: Needs work » Needs review
FileSize
2.86 KB

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

shabana.navas’s picture

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.