In flag_weights_set_flag it says $handlers instead of $handler when calling flag_weights_set_weight ( $handlers->content_type). Can't see anywhere else where $handlers is used; if this is related to how the module is used, then close this but I can't imagine how that ever worked.

In related (aka how I noticed the typo) popped out this function to flag/weight using an existing flag. (The flag using content type never worked for me btw, don't currently really see the purpose of it).

function flag_weights_set_flag_with_flag($flag_name, $content_id, $account = NULL, $weight = 0) {
  $handler =  flag_get_flag($flag_name) ;
  $ok = $handler->flag('flag', $content_id, $account);
  if ($ok && $weight != 0) {
    if (!isset($account)) {
      $account = $GLOBALS['user'];
    }
    flag_weights_set_weight($handler->fid, $handler->content_type, $content_id, $account->uid, $weight);
  }
  return $ok;
}

Comments

avpaderno’s picture

Title: Possible typo, flag_weights_set_flag » Reference to a not initialized variable in flag_weights_set_flag()
markus_petrux’s picture

Status: Active » Reviewed & tested by the community
-    flag_weights_set_weight($handler->fid, $handlers->content_type, $content_id, $account->uid, $weight);
+    flag_weights_set_weight($handler->fid, $handler->content_type, $content_id, $account->uid, $weight);

Please, let me know if you wish a proper patch for this.

lyricnz’s picture

Status: Reviewed & tested by the community » Needs review

Applied the handler/handlers patch to -dev.

Will consider the new function another day (setting back to "needs review"). Thanks!

lyricnz’s picture

Status: Needs review » Fixed

Committed a new method as described above. Agree that flagging by flag-name makes more sense than by content-type, but changing the API now would break anyone who is using it, in unexpected ways.

http://drupal.org/cvs?commit=256248

Status: Fixed » Closed (fixed)

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