Hi. I cannot upgrade to 6.x yet for a variety of reasons and I really need the 5.x version of Apply for role to send an e-mail to the user when their application is approved.

I installed the Actions module, which is a back-port of the 6.x actions/trigger functionality that is now in core. There's not a lot of documentation for adding custom triggers though. I then created a new module which depends on Apply_for_role and Actions to put the new code (since I don't know if you want to make 5.x depend on Actions for this one feature). I'm looking at the changes in the 6.x -dev module to try to figure out which functions were added for this feature and copy them to the new module, making sure to deal with any differences between 6.x actions/triggers and the 5.x Actions module.

So, this is really a combination feature and support request. I need this done ASAP so if anyone is around to give advice contact me through my contact form. I'll also contribute back what I've done to Soren can decide what to do with it. So my request is:

Please point me to the functions which are responsible for creating custom triggers and actions. If you know of any, please point me to documentation besides hook_hook_info on api.drupal.org to help me make sense of this.

Maria

Comments

Soren Jones’s picture

Maria,

If you can wait, 6-type actions integration will be backported to 5 within the next 6 weeks.
Maybe sooner than later....

If you can't wait:
apply_for_role_hook_info()
apply_for_role_action_info_alter()
apply_for_role_apply_for_role()

(Am I forgetting anything?)

Remember that it's:
if (!module_exists('actions'))
[NOT if (!module_exists('trigger'))]

...so it won't be a dependency.

See the handbook page on Drupal 6.x actions for more information about Drupal 6 actions.

Best,
Soren

justmagicmaria’s picture

Thanks, Soren. I can't wait and you confirmed that I got the three I thought were needed (and I discovered the module_exists difference the hard way, LOL!)

Almost working-- where are the "token_actions_XXX" actions defined? I tried enabling token module and actions_token_email but can't find them.

Thanks for your help!!

Maria

Soren Jones’s picture

Right!

In 6, in apply_for_role.token.inc.

Good luck!

Night,
Soren

justmagicmaria’s picture

Ah! I'm sooo close...

I can see the apply_for_role triggers in the list but when I associate them with actions (Send email and Send tokenized email are both showing up in the select list), the actions never actually fire.

And I can't get the apply_for_role tokens to appear in the "available tokens" list in the "Send tokened email" configuration screen. I tried moving the apply_for_role_token_values and apply_for_role_token_list functions into apply_for_role.module. When are these supposed to get called? (I added watchdog debug calls and they're not getting logged.)

Sigh.

Maria

Soren Jones’s picture

Look at apply_for_role_add_apply in 6.

You'll see:

      $apply = (object) array('uid' => $uid, 'rid' => $rid, 'approved' => 0, 'apply_date' => time());
      drupal_write_record('users_roles_apply', $apply);

      module_invoke_all('apply_for_role', 'apply', $apply);

module_invoke_all() is the important bit.

I hope that helps.

NOTE:
drupal_write_record in 6 is replacing the INSERT in 5. There's no durpal_write_record in 5.

chadchandler’s picture

I did something like this in Workflow-NG , make sure you fill in the appropriate fields. Import this code into your Workflow-NG.

array (
  'cfg_3' => 
  array (
    '#type' => 'configuration',
    '#label' => 'Account Turned Active',
    '#event' => 'user_update',
    '#weight' => '0',
    '#id' => 1,
    '#module' => 'workflow-ng',
    '#active' => 1,
    '#altered' => false,
    0 => 
    array (
      '#type' => 'condition',
      '#name' => 'workflow_ng_condition_custom_php',
      '#id' => 2,
      '#settings' => 
      array (
        'php' => 'return ($account_unchanged->status == 0) && ($account->status == 1);',
        'used_arguments' => 
        array (
        ),
        'used_php_arguments' => 
        array (
          0 => 'account',
          1 => 'account_unchanged',
        ),
      ),
    ),
    1 => 
    array (
      '#label' => 'Send a mail to an arbitrary mail address',
      '#id' => 3,
      '#name' => 'workflow_ng_action_mail',
      '#type' => 'action',
      '#settings' => 
      array (
        'to' => '[account:mail],youremail@email.com',
        'to_args' => 
        array (
          0 => 'account',
        ),
        'from' => 'youremail@email.com',
        'from_args' => 
        array (
        ),
        'subject' => 'Your Account for the Website has been Activated!',
        'subject_args' => 
        array (
        ),
        'message' => 'Dear [account:user],

Your account has been activated for the Website.  You can login using the information that was previously emailed to you by the system.  You can modify your account information at any time by clicking [account_unchanged:site-url][account:account-edit].

If you have any questions, please contact Site Admin at youremail@email.com.',
        'message_args' => 
        array (
          0 => 'account',
          1 => 'account_unchanged',
        ),
      ),
    ),
    '#name' => 'cfg_3',
  ),
)
Soren Jones’s picture

If Prodigy's solution doesn't work for you, a new 5 -dev has been committed and will be available for download within the next 12 hours. It's backport of 6.x-1.7 with support for 6 style Actions. It won't get you 100% of the way there, but it should shorten the trip. You'll probably want to wrap a custom email action in a module, maybe using the "Actions token email" module as a guide or skeleton.

justmagicmaria’s picture

Thanks, guys. I have got it working with a modified version of Actions token email that takes an apply object since ATE expects a node.

Actions is cool and flexible. I'm putting it to other uses now... like auto-approving up to a designated number of users for a particular role.

Maria

Soren Jones’s picture

Status: Active » Fixed

Maria,

Great! Glad you got it sorted out.

Let me know if you run into any bugs in the 5 -dev.
I'll try to get a new release out before too long.

Anyway, marking this as fixed.

Thanks,
Soren

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

ckng’s picture

FYI, #6 workflow_ng will not work as user_update is not fired in apply_for_role module.
See my patch in #333770: Missing proper user update, after_update event for workflow_ng to work properly.