1

I am trying to make a rule which when acted upon will send an email with custom details based on the rule arguments.

I made my rule event and that's all working fine it shows up, but when I add an action to "Send mail" and then look at all of the Replacement patterns non of my tokens show up, only site-information tokens show up.

Token Functions

/**
 * Implementation of hook_token_list()
 */
function mahjong_token_list($type = 'all') {
  if ($type == 'all' || $type == 'mahjong') {
    $tokens['mahjong'] = array(
      'package_name' => t('The name of the package'),
    );
  }

  return $tokens;
}

/**
 * Implementation of hook token api
 */
function mahjong_token_values($type, $object = NULL, $options = array()) {
  $tokens = array();
  var_dump($object);
  if ($object) {
    if ($type == 'mahjong') {
      $tokens = array(
        'user_name' => $object->name,
        'user_email' => $object->email,
        'user_score' => $object->score,
      );
    }
  }

  return $tokens;
}

Rules Function

function mahjong_rules_event_info() {
  return array(
    'mahjong_won' => array(
      'label' => t('A person won the mahjong game.'),
      'module' => 'mahjong',
      'group' => 'Rules',
      'arguments' => array(
        'user' => array('type' => 'mahjong', 'label' => t('The user who won the mahjong game.')),
      ),
    ),
  );
}

What am I doing wrong? How can I get the data from the rules argument pass to the action to send an email?

0

If "mahjong" is just an arbitrary object type, you need to declare it to Rules using hook_rules_data_info and specify the "token type" so that Rules knows what to pass to the token API.

But if the "mahjong" object is a Drupal User entity, you shouldn't need to implement hook_token_* at all.

Instead, when you define your Rules event, the argument should be of type "user". Rules will then know what fields are defined on the entity.

  • It ended up being a mix of that and me using Drupal 6 functions not 7. – Steven Jul 3 '14 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.