The clean-up work in #2202969: clean up flag() and its low-level helpers is great, but flagging_insert() is now a bit on the big side.
I think it would make sense to move the Rules stuff out to a helper method, so replace this:
// Invoke Rules event.
if (module_exists('rules')) {
$event_name = 'flag_flagged_' . $this->name;
// We only support flags on entities.
if (entity_get_info($this->entity_type)) {
$variables = array(
'flag' => $this,
'flagged_' . $this->entity_type => $entity_id,
'flagging_user' => $account,
'flagging' => $this->get_flagging($entity_id, $account->uid),
);
rules_invoke_event_by_args($event_name, $variables);
}
}
with something like this:
// Invoke Rules event.
if (module_exists('rules')) {
$this->invoke_rules_event(ACTION, $flagging, whatever other params we need);
}
and let the helper method do the work of building up the stuff that needs to be passed to Rules.
While the goal of #2202969: clean up flag() and its low-level helpers was to remove tangled helper methods, I think that this is a good candidate for a helper: it's a single operation, which requires quite a few lines of code, and which is perfectly described by the method call to invoke_rules_event(). It's also code that occurs twice at the moment.
Postponed because #2250543: pointless call to get_flagging() needs to get in first.
Comment | File | Size | Author |
---|---|---|---|
#1 | 2254171.flag_.rules-helper-method.patch | 3.44 KB | joachim |
Comments
Comment #1
joachim CreditAttribution: joachim commentedBecause this is now in its own method, we also get to use inheritance to determine whether Rules can actually be invoked, rather than having to call entity_get_info().
Comment #2
joachim CreditAttribution: joachim commented