Tokens described in hook_pet_substitutions_alter() will not be replaced unless they are real tokens which was implemented using hook_tokens() and etc.
Sometime you need to have custom tokens in your email but they couldn't be tokenized. For example, when you got wrong request and want to send some information to site admin about this request but there is no need to store it to database.

This patch after replacing all existing tokens allow you to replace custom tokens (which actually not tokens at all).
Probably you'll need patch https://drupal.org/node/2087959 to get it working.

Usage:

$params = array(
  'message' => t('Error message with code.'),
);
pet_send_mail('lead_provider_' . $mail_key, $recipients, $params);

then you should implement:

/**
 * Add custom token objects.
 */
function modulename_pet_substitutions_alter(&$substitutions, $params) {
  if (isset($params['pet_options']) && is_array($params['pet_options'])) {
    $substitutions['[message]'] = $params['pet_options']['message'];
  }
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

VladSavitsky’s picture

FileSize
781 bytes
VladSavitsky’s picture

Status: Active » Needs review
VladSavitsky’s picture

FileSize
1.42 KB

Fixed issue when user with this email is existing user at site and pet adds user object to the array of substitutions.

sumanthkumarc’s picture

Issue summary: View changes

The patch works for me. But the replacement must of format $type:$name, otherwise token module won't replace it. Also we need to implement hook_tokens() to replace your custom token.

Sharique’s picture

Issue tags: +Need tests

It would be nice, if some tests are written for this.