Rules action "Trim flag" should be ported to Flag 8.x..

CommentFileSizeAuthor
#3 flag-2470645-3-trim_flag.patch4.24 KBczigor
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

czigor’s picture

czigor’s picture

Assigned: Unassigned » czigor
czigor’s picture

Status: Active » Needs review
FileSize
4.24 KB

This patch is without tests, I would like someone to confirm if the direction is right.

1. I readded the flag_trim_flag() function removed in a8a0aa5ead5d8e334b576314362ef6f279cf6216 as a method of the Flag entity.
2. As anonymous flaggings are not implemented yet in 8.x, I omitted it.

czigor’s picture

Assigned: czigor » Unassigned

Status: Needs review » Needs work

The last submitted patch, 3: flag-2470645-3-trim_flag.patch, failed testing.

klausi’s picture

+++ b/src/Plugin/Action/FlagTrim.php
@@ -0,0 +1,62 @@
+ *   },

I think that trailing comma in the annotation breaks the tests.

joachim’s picture

I remember an issue was filed on Doctrine to allow trailing commas.

joachim’s picture

+++ b/src/Entity/Flag.php
@@ -553,6 +554,48 @@ class Flag extends ConfigEntityBundleBase implements FlagInterface {
 
   /**
+   * Trim a flag to a certain size.
+   *
+   * @param UserInterface $account
+   *   The user object on behalf the trimming will occur.
+   * @param $cutoff_size
+   *   The number of flaggings allowed. Any flaggings beyond that will be trimmed.
+   * @param $trim_newest
+   *   An optional boolean indicating whether to trim the newest flags.
+   * @param $permissions_check
+   *   (optional) A boolean indicating whether to skip permissions.
+   *   This will trim the flag if $permissions_check is TRUE even if the user
+   *   doesn't have the permission to flag/unflag.
+   */
+  public function trim(UserInterface $account, $cutoff_size, $trim_newest, $permissions_check = FALSE) {

This probably belongs in the service rather than the flag class. Or at least, there's discussion going on at the moment about whether the flag/unflag() methods belong in the service of the flag class, and this should go in the same place.