I got an entity type containing a long text field. If a user types in a certain character pattern ("xX" for example), this string "xX" should replaced with "×" (the proper symbol for multiplication) after saving the entity. I looked at hook_field_presave and hook_field_attach_presave but don't know how to use correctly.
This is the code i tried in a custom module:
function replace_multiplication_symbol_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
if ($field['name'] == 'field_technical_description') {
foreach ($items as $delta => $item) {
if (isset($item['value'])) {
$items[$delta]['value'] = str_replace('xX', '×', $items[$delta]['value']);;
}
}
}
}