Index: webform.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.info,v
retrieving revision 1.8
diff -u -p -r1.8 webform.info
--- webform.info 3 Apr 2010 02:49:23 -0000 1.8
+++ webform.info 18 Dec 2010 04:56:11 -0000
@@ -7,6 +7,7 @@ configure = admin/config/content/webform
files[] = webform.module
files[] = webform.install
+files[] = webform.tokens.inc
files[] = components/date.inc
files[] = components/email.inc
Index: webform.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.module,v
retrieving revision 1.269
diff -u -p -r1.269 webform.module
--- webform.module 5 Nov 2010 01:05:53 -0000 1.269
+++ webform.module 18 Dec 2010 04:56:13 -0000
@@ -2711,6 +2711,7 @@ function _webform_filter_values($string,
$find = array_keys($safe_replacements);
$replace = array_values($safe_replacements);
+
$string = str_replace($find, $replace, $string);
// Clean up any unused tokens.
@@ -2826,14 +2827,17 @@ function theme_webform_token_help($varia
}
$fieldset = array(
- '#title' => t('Token values'),
'#type' => 'fieldset',
+ '#title' => t('Token values'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
- '#children' => '
' . $output . '
',
'#attributes' => array('class' => array('collapsible', 'collapsed')),
);
- return theme('fieldset', array('element' => $fieldset));
+ $fieldset['token_tree'] = array(
+ '#theme' => 'token_tree',
+ '#token_types' => array('node'),
+ );
+ return render($fieldset);
}
function _webform_safe_name($name) {
Index: webform.tokens.inc
===================================================================
RCS file: webform.tokens.inc
diff -N webform.tokens.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ webform.tokens.inc 18 Dec 2010 04:56:13 -0000
@@ -0,0 +1,124 @@
+ t('Webform submission'),
+ 'description' => t('Tokens related to webform submissions.'),
+ 'needs-data' => 'webform-submission',
+ );
+ $info['tokens']['webform-submission']['sid'] = array(
+ 'name' => t('Submission ID'),
+ 'description' => t('The unique indentifier for the webform submission.'),
+ );
+ $info['tokens']['webform-submission']['node'] = array(
+ 'name' => t('Node'),
+ 'description' => t('The webform content that the submission came from.'),
+ 'type' => 'node',
+ );
+ $info['tokens']['webform-submission']['date'] = array(
+ 'name' => t('Date submitted'),
+ 'description' => t('The date the webform was submitted.'),
+ 'type' => 'date',
+ );
+ $info['tokens']['webform-submission']['ip-address'] = array(
+ 'name' => t('IP address'),
+ 'description' => t('The IP address that was used when submitting the webform.'),
+ );
+ $info['tokens']['webform-submission']['user'] = array(
+ 'name' => t('Submitter'),
+ 'description' => t('The user that submitted the webform result.'),
+ 'type' => 'user',
+ );
+ $info['tokens']['webform-submission']['path'] = array(
+ 'name' => t('URL'),
+ 'description' => t('The URL alias to view the webform result.'),
+ );
+ $info['tokens']['webform-submission']['url'] = array(
+ 'name' => t('URL'),
+ 'description' => t('The URL to view the webform result.'),
+ );
+ $info['tokens']['webform-submission']['edit-url'] = array(
+ 'name' => t('Edit URL'),
+ 'description' => t('The URL to edit the webform result.'),
+ );
+
+ return $info;
+}
+
+/**
+ * Implements hook_tokens().
+ */
+function webform_tokens($type, $tokens, array $data = array(), array $options = array()) {
+ $replacements = array();
+
+ $url_options = array('absolute' => TRUE);
+ if (isset($options['language'])) {
+ $url_options['language'] = $options['language'];
+ $language_code = $options['language']->language;
+ }
+ else {
+ $language_code = NULL;
+ }
+
+ $sanitize = !empty($options['sanitize']);
+
+ // Webform submission tokens.
+ if ($type == 'webform-submission' && !empty($data['webform-submission'])) {
+ $submission = $data['webform-submission'];
+
+ foreach ($tokens as $name => $original) {
+ switch ($name) {
+ case 'sid':
+ $replacements[$original] = $submission->sid;
+ break;
+ case 'node':
+ $node = node_load($submission->nid);
+ $replacements[$original] = $sanitize ? check_plain($node->title) : $node->title;
+ break;
+ case 'date':
+ $replacements[$original] = format_date($submission->submitted, 'medium', '', NULL, $language_code);
+ break;
+ case 'ip-address':
+ $replacements[$original] = $sanitize ? check_plain($submission->remote_addr) : $submission->remote_addr;
+ break;
+ case 'user':
+ $account = user_load($submission->uid);
+ $name = format_username($account);
+ $replacements[$original] = $sanitize ? check_plain($name) : $name;
+ break;
+ case 'path':
+ $alias = drupal_get_path_alias("node/{$submission->nid}/submission/{$submission->sid}", $language_code);
+ $replacements[$original] = $sanitize ? check_plain($alias) : $alias;
+ break;
+ case 'url':
+ $replacements[$original] = url("node/{$submission->nid}/submission/{$submission->sid}", $url_options);
+ break;
+ case 'edit-url':
+ $replacements[$original] = url("node/{$submission->nid}/submission/{$submission->sid}/edit", $url_options);
+ break;
+ }
+ }
+
+ // Chained token relationships.
+ if (($node_tokens = token_find_with_prefix($tokens, 'node')) && $node = node_load($submission->nid)) {
+ $replacements += token_generate('node', $node_tokens, array('node' => $node), $options);
+ }
+ if ($date_tokens = token_find_with_prefix($tokens, 'date')) {
+ $replacements += token_generate('date', $date_tokens, array('date' => $submission->submitted), $options);
+ }
+ if (($user_tokens = token_find_with_prefix($tokens, 'user')) && $account = user_load($submission->uid)) {
+ $replacements += token_generate('user', $user_tokens, array('user' => $account), $options);
+ }
+ }
+
+ return $replacements;
+}
Index: webform_hooks.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform_hooks.php,v
retrieving revision 1.19
diff -u -p -r1.19 webform_hooks.php
--- webform_hooks.php 17 Oct 2010 21:52:41 -0000 1.19
+++ webform_hooks.php 18 Dec 2010 04:56:13 -0000
@@ -296,7 +296,7 @@ function hook_webform_component_info() {
// always be displayed conditionally, regardless of this setting.
// Defaults to TRUE.
'conditional' => TRUE,
- // If this field allows other fields to be grouped within it (like a
+ // If this field allows other fields to be grouped within it (like a
// fieldset or tabs). Defaults to FALSE.
'group' => FALSE,
// If this field saves a file that can be used as an e-mail attachment.
@@ -428,7 +428,7 @@ function _webform_render_component($comp
/**
* Display the result of a submission for a component.
- *
+ *
* The output of this function will be displayed under the "Results" tab then
* "Submissions". This should output the saved data in some reasonable manner.
*
@@ -546,7 +546,7 @@ function _webform_theme_component() {
/**
* Calculate and returns statistics about results for this component.
- *
+ *
* This takes into account all submissions to this webform. The output of this
* function will be displayed under the "Results" tab then "Analysis".
*
Index: includes/webform.emails.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/webform/includes/webform.emails.inc,v
retrieving revision 1.22
diff -u -p -r1.22 webform.emails.inc
--- includes/webform.emails.inc 22 Oct 2010 23:44:08 -0000 1.22
+++ includes/webform.emails.inc 18 Dec 2010 04:56:13 -0000
@@ -296,7 +296,8 @@ function webform_email_edit_form($form,
);
$form['template']['tokens'] = array(
- '#value' => theme('webform_token_help'),
+ '#theme' => 'token_tree',
+ '#token_types' => array('webform-submission'),
);
$form['template']['components'] = array(