function field_token_value_field_presave in Field Token Value 7
Implements hook_field_presave().
File
- ./
field_token_value.module, line 202 - Provides a field type allowing the value to be set using tokens.
Code
function field_token_value_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
$remove_empty = $instance['settings']['remove_empty'];
$field_value = token_replace($instance['settings']['field_value'], array(
$entity_type => $entity,
), array(
'clear' => $remove_empty,
));
// Save the updated field value and ensure there is no HTML.
$items[0]['value'] = trim(preg_replace('#<[^>]+>#', ' ', $field_value));
}