hook_field_presave

Versions
mediamosa-21
hook_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items)

Define custom presave behavior for this module's field types.

Parameters

$entity_type The type of $entity.

$entity The entity for the operation.

$field The field structure for the operation.

$instance The instance structure for $field on $entity's bundle.

$langcode The language associated to $items.

$items $entity->{$field['field_name']}[$langcode], or an empty array if unset.

Related topics

Code

modules/field/field.api.php, line 405

<?php
function hook_field_presave($entity_type, $entity, $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']);
      }
    }
  }
}
?>