Commit 2218f528 authored by Dries's avatar Dries
Browse files

- Patch #631048 by yched: number rounding should not be done by widgets.

parent c62f56c8
......@@ -397,6 +397,15 @@ function hook_field_validate($obj_type, $object, $field, $instance, $langcode, &
* $object->{$field['field_name']}[$langcode], or an empty array if unset.
*/
function hook_field_presave($obj_type, $object, $field, $instance, $langcode, &$items) {
if ($field['type'] == 'number_decimal') {
// Let PHP round the value to ensure consistent behavior across storage
// backends.
foreach ($items as $delta => $item) {
if (isset($item['value'])) {
$items[$delta]['value'] = round($item['value'], $field['settings']['scale']);
}
}
}
}
/**
......
......@@ -191,6 +191,21 @@ function number_field_validate($obj_type, $object, $field, $instance, $langcode,
}
}
/**
* Implements hook_field_presave().
*/
function number_field_presave($obj_type, $object, $field, $instance, $langcode, &$items) {
if ($field['type'] == 'number_decimal') {
// Let PHP round the value to ensure consistent behavior across storage
// backends.
foreach ($items as $delta => $item) {
if (isset($item['value'])) {
$items[$delta]['value'] = round($item['value'], $field['settings']['scale']);
}
}
}
}
/**
* Implement hook_content_is_empty().
*/
......@@ -349,12 +364,6 @@ function number_field_widget_validate($element, &$form_state) {
if ($type == 'decimal' || $type == 'float') {
$value = strtr($value, $field['settings']['decimal_separator'], '.');
}
// Let PHP round the value to ensure consistent behavior across storage
// backends.
// @todo This should be done at field level.
if ($type == 'decimal') {
$value = round($value, $field['settings']['scale']);
}
form_set_value($element, $value, $form_state);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment