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.

CommentFileSizeAuthor
#1 2254171.flag_.rules-helper-method.patch3.44 KBjoachim
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim’s picture

Status: Postponed » Needs review
FileSize
3.44 KB

Because 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().

joachim’s picture

Status: Needs review » Fixed

  • Commit 92532e3 on 7.x-3.x by joachim:
    Issue #2254171 by joachim: Moved Rules event invocation to a helper...

Status: Fixed » Closed (fixed)

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