function pet_substitutions in Previewable email templates 6
Same name and namespace in other branches
- 8.4 pet.module \pet_substitutions()
- 8 pet.module \pet_substitutions()
- 7 pet.module \pet_substitutions()
Load the token objects for a PET template in preparation for token substitution.
2 calls to pet_substitutions()
- pet_make_preview in ./
pet.admin.inc - Generate a preview of the tokenized email for the first in the list.
- pet_send_one_mail in ./
pet.module - Send one email, with token substitution.
File
- ./
pet.module, line 251 - Previewable E-mail Template module.
Code
function pet_substitutions($pet, $params) {
$uid = $params['pet_uid'];
$nid = $params['pet_nid'];
// Standard substitutions
$substitutions['global'] = NULL;
if (!empty($uid)) {
$user = user_load(array(
'uid' => $uid,
));
$substitutions['user'] = $user;
}
if (!empty($nid)) {
// Need the reset to pick up any changes to the node
$node = node_load($nid, $revision = NULL, $reset = TRUE);
$substitutions['node'] = $node;
}
// Custom substitutions
$pairs = explode("\n", $pet->object_types);
foreach ($pairs as $pair) {
if (!empty($pair)) {
list($type, $object) = explode('|', $pair);
$object = trim($object);
if ($object == 'node' && !empty($nid)) {
$substitutions[$type] = $node;
}
elseif ($object == 'user' && !empty($uid)) {
$substitutions[$type] = $user;
}
else {
$substitutions[$type] = NULL;
}
}
}
// Give modules the opportunity to add their own token types/objects
drupal_alter('pet_substitutions', $substitutions, $params);
return $substitutions;
}