commerce_registration.tokens.inc in Commerce Registration 7.2
Same filename and directory in other branches
Token support for Commerce Registration.
File
commerce_registration.tokens.incView source
<?php
/**
* @file
* Token support for Commerce Registration.
*/
/**
* Implements hook_token_info().
*/
function commerce_registration_token_info() {
$info['types']['commerce-registration'] = array(
'name' => t('Commerce Registration'),
'description' => t('Tokens related to commerce registrations.'),
);
$info['tokens']['commerce-registration']['registration-index'] = array(
'name' => t('Registration Index'),
'description' => t('The numerical index of the registration for a product.'),
);
return $info;
}
/**
* Implements hook_token_info_alter().
*/
function commerce_registration_token_info_alter(&$data) {
// Add token for Commerce Order to Registrations.
$data['tokens']['registration']['commerce_order'] = array(
'name' => t('Commerce Order ID'),
'description' => t('The Commerce order number that the registration belongs to.'),
);
}
/**
* Implements hook_tokens().
*/
function commerce_registration_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
if ($type == 'registration' && !empty($data['registration'])) {
$reg = $data['registration'];
foreach ($tokens as $name => $original) {
switch ($name) {
case "commerce_order":
$replacements[$original] = $reg->order_id;
break;
}
}
}
if ($type == 'commerce-registration' && !empty($data['commerce-registration'])) {
$commerce_registration = $data['commerce-registration'];
foreach ($tokens as $name => $original) {
switch ($name) {
case 'registration-index':
$replacements[$original] = $commerce_registration['index'];
break;
}
}
}
return $replacements;
}
Functions
Name![]() |
Description |
---|---|
commerce_registration_tokens | Implements hook_tokens(). |
commerce_registration_token_info | Implements hook_token_info(). |
commerce_registration_token_info_alter | Implements hook_token_info_alter(). |