diff --git a/includes/flag/flag_flag.inc b/includes/flag/flag_flag.inc index 2571044..e782d87 100644 --- a/includes/flag/flag_flag.inc +++ b/includes/flag/flag_flag.inc @@ -788,19 +788,23 @@ class flag_flag { } } elseif ($action == 'flag') { - // Invoke hook_entity_presave(). - module_invoke_all('entity_presave', $flagging, 'flagging'); - if ($this->uses_anonymous_cookies()) { $this->_flag_anonymous($entity_id); } + + // By definition there is no flagging entity, but we may have been passed + // one in to save. + if (!isset($flagging)) { + // Construct a new flagging object if we don't have one. + $flagging = $this->new_flagging($entity_id, $uid, $sid); + } + + // Invoke hook_entity_presave(). + module_invoke_all('entity_presave', $flagging, 'flagging'); + if (!$flagged) { - // The entity is unflagged. By definition there is no flagging entity, - // but we may have been passed one in to save. - if (!isset($flagging)) { - // Construct a new flagging object if we don't have one. - $flagging = $this->new_flagging($entity_id, $uid, $sid); - } + // The entity is unflagged. + // Save the flagging entity (just our table). $flagging_id = $this->_flag($entity_id, $uid, $sid); // The _flag() method is a plain DB record writer, so it's a bit @@ -833,7 +837,7 @@ class flag_flag { // Except in the case a $flagging object is passed in: in this case // we're, for example, arriving from an editing form and need to update // the entity. - if ($flagging) { + if (!empty($flagging->flagging_id)) { $this->_update_flagging($flagging); } }