function webform_rules_prepare_component_value in Webform Rules 6
Same name and namespace in other branches
- 7 webform_rules.module \webform_rules_prepare_component_value()
Prepare component value for output. Code adapted from drupal_to_js().
Parameters
$component_value: Value of submitted component.
$raw: If TRUE, leave all values unfiltered.
1 call to webform_rules_prepare_component_value()
- webform_rules_token_values in ./
webform_rules.module - Implementation of hook_token_values().
File
- ./
webform_rules.module, line 238 - Adds rules integration for webform submissions.
Code
function webform_rules_prepare_component_value($component_value, $raw = FALSE) {
switch (gettype($component_value)) {
case 'boolean':
return $component_value ? 'true' : 'false';
// Lowercase necessary!
case 'integer':
case 'double':
return $var;
case 'resource':
case 'string':
return $raw ? $component_value : check_plain($component_value);
case 'array':
// If the array is empty or if it has sequential whole number keys
// starting with 0, it's not associative so we can go ahead and
// convert it as an array.
if (empty($component_value) || array_keys($component_value) === range(0, sizeof($component_value) - 1)) {
$output = array();
foreach ($component_value as $v) {
$output[] = webform_rules_prepare_component_value($v, $raw);
}
return implode(', ', $output);
}
// Otherwise, fall through to convert the array as an object.
// This is usefull for more readable output.
case 'object':
$output = array();
foreach ($component_value as $k => $v) {
$output[] = webform_rules_prepare_component_value(strval($k), $raw) . ': ' . webform_rules_prepare_component_value($v, $raw);
}
return implode(', ', $output);
default:
return 'null';
}
}