-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathform_rules.module
More file actions
65 lines (63 loc) · 2.52 KB
/
form_rules.module
File metadata and controls
65 lines (63 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* @file
* Provides special token to use with pathauto.
*
* @see http://drupal.org/node/1308488
*/
/**
* Provide information about our custom placeholder/token.
*
* @see http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_token_info/7
* @see http://api.lullabot.com/token_example_token_info/7
* @return array
* An associative array of available tokens and token types.
*/
function form_rules_token_info() {
$info['types']['form'] = array(
'name' => t('Form'),
'description' => t('Tokens related to webform submissions.'),
//'needs-data' => 'webform-submission',
);
$info['tokens']['form']['contribution_total_amount'] = array(
'name' => t('Contribution Amount'),
'description' => t('The final amount of the contribution.'),
);
return $info;
}
/**
* Provide replacement values for placeholder tokens.
*
* @see http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_tokens/7
* @see http://api.lullabot.com/token_example_tokens/7
* @param string $type
* The machine-readable name of the type (group) of token being replaced, such
* as 'node', 'user', or another type defined by a hook_token_info()
* implementation.
* @param array $tokens
* An array of tokens to be replaced. The keys are the machine-readable token
* names, and the values are the raw [type:token] strings that appeared in the
* original text.
* @param array $data (optional)
* An associative array of data objects to be used when generating replacement
* values, as supplied in the $data parameter to token_replace().
* @param array $options (optional)
* An associative array of options for token replacement; see token_replace()
* for possible values.
* @return array
* An associative array of replacement values, keyed by the raw [type:token]
* strings from the original text.
*/
function form_rules_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
$sanitize = !empty($options['sanitize']);
if ($type == 'form' && !empty($_POST['submitted'])) {
foreach ($tokens as $name => $original) {
$form[$name] = $_POST['submitted'][$name];
$replacements[$original] = $form[$name];
}
$replacements['[form:contribution_total_amount]'] = $_POST['submitted']['price_for_submission']*
($_POST['submitted']['how_many_brand_entries_would_you_like_to_submit']+$_POST['submitted']['how_many_new_products_would_you_like_to_submit']);
}
return $replacements;
}