diff --git a/modules/system.eval.inc b/modules/system.eval.inc index a56bbe9..83526a9 100644 --- a/modules/system.eval.inc +++ b/modules/system.eval.inc @@ -152,7 +152,9 @@ class RulesTokenEvaluator extends RulesDataInputEvaluator { public function prepare($text, $var_info) { $text = is_array($text) ? implode('', $text) : $text; // Skip this evaluator if there are no tokens. - $this->setting = token_scan($text) ? TRUE : NULL; + // TODO: Make our own token_scan variant based on the RulesTokenEvaluator. + // see: http://drupal.org/node/1774630 + $this->setting = token_scan($text) || _rules_system_find_variables($text) ? TRUE : NULL; } /** @@ -170,6 +172,18 @@ class RulesTokenEvaluator extends RulesDataInputEvaluator { $data = array(); // We also support replacing tokens in a list of textual values. $whole_text = is_array($text) ? implode('', $text) : $text; + + // Process variable tokens. + foreach (_rules_system_find_variables($whole_text) as $var_name => $token) { + $var_name = str_replace('-', '_', $var_name); + if (isset($var_info[$var_name]) && _rules_system_valid_text_type($var_info[$var_name]['type'])) { + $type = $var_info[$var_name]['type']; + $data = rules_unwrap_data(array($type => $state->get($var_name)), array($type => $var_info[$var_name])); + $replacements[$token] = $data[$type]; + } + } + + // Process real tokens. foreach (token_scan($whole_text) as $var_name => $tokens) { $var_name = str_replace('-', '_', $var_name); if (isset($var_info[$var_name]) && ($token_type = _rules_system_token_map_type($var_info[$var_name]['type']))) { @@ -209,6 +223,26 @@ class RulesTokenEvaluator extends RulesDataInputEvaluator { '#description' => t('Note that token replacements containing chained objects – such as [node:author:uid] – are not listed here, but are still available. The data selection input mode may help you find more complex replacement patterns. See the online documentation for more information about complex replacement patterns.', array('@url' => rules_external_help('chained-tokens'))), ); + + // Add token information for variables. + $rows = array(); + foreach ($var_info as $var_name => $info) { + if (_rules_system_valid_text_type($info['type'])) { + $token = '[' . str_replace('_', '-', $var_name) . ']'; + $description = !empty($info['description']) ? $info['description'] : ''; + $rows[] = array(check_plain($token), check_plain($info['label']), check_plain($description)); + } + }; + if ($rows) { + $render['rules_variables'] = array( + '#theme' => 'table', + '#header' => array(t('Token'), t('Label'), t('Description')), + '#prefix' => '