function rules_action_data_convert

Action: Convert a value.

Related topics

1 string reference to 'rules_action_data_convert'
rules_data_action_info in modules/data.rules.inc
Implements hook_rules_action_info() on behalf of the pseudo data module.

File

modules/data.eval.inc, line 197

Code

function rules_action_data_convert($arguments, RulesPlugin $element, $state) {
    $value_info = $element->getArgumentInfo('value');
    $from_type = $value_info['type'];
    $target_type = $arguments['type'];
    // First apply the rounding behavior if given.
    if (isset($arguments['rounding_behavior'])) {
        switch ($arguments['rounding_behavior']) {
            case 'up':
                $arguments['value'] = ceil($arguments['value']);
                break;
            case 'down':
                $arguments['value'] = floor($arguments['value']);
                break;
            default:
            case 'round':
                $arguments['value'] = round($arguments['value']);
                break;
        }
    }
    switch ($target_type) {
        case 'decimal':
            $result = floatval($arguments['value']);
            break;
        case 'integer':
            $result = intval($arguments['value']);
            break;
        case 'text':
            $result = strval($arguments['value']);
            break;
        case 'token':
            $result = strval($arguments['value']);
            break;
    }
    return array(
        'conversion_result' => $result,
    );
}