diff --git b/entityreference.module a/entityreference.module index cc30a34..1db0670 100644 --- b/entityreference.module +++ a/entityreference.module @@ -243,6 +243,34 @@ function entityreference_field_validate($entity_type, $entity, $field, $instance * Adds the target type to the field data structure when saving. */ function entityreference_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) { + if (!empty($field['settings']['handler_settings']['lock_revision'])) { + $dest_entity_type = $field['settings']['target_type']; + if (isset($entity->original)) { + $original_items = field_get_items($entity_type, $entity->original, $field['field_name']); + } + else { + $ids = entity_extract_ids($entity_type, $entity); + $original = entity_load_unchanged($entity_type, $ids[0]); + $original_items = field_get_items($entity_type, $original, $field['field_name']); + } + foreach ($items as $key => $val) { + $ref_entity = entity_load_single($dest_entity_type, $val['target_id']); + $ref_ids = entity_extract_ids($dest_entity_type, $ref_entity); + // find the original item, which does not have the same delta per se. + $original_revision = FALSE; + foreach ($original_items as $original_item) { + if ($original_item['target_id'] == $val['target_id']) { + $original_revision = isset($original_item['revision_id']) ? $original_item['revision_id'] : FALSE; + } + } + if (isset($ref_ids[1]) && is_numeric($ref_ids[1]) && !$original_revision) { + $items[$key]['revision_id'] = $ref_ids[1]; + } + else if ($original_revision) { + $items[$key]['revision_id'] = $original_revision; + } + } + } // Invoke the behaviors. foreach (entityreference_get_behavior_handlers($field, $instance) as $handler) { $handler->presave($entity_type, $entity, $field, $instance, $langcode, $items);