How do I set entity reference revision value for a field? I have two fields, field_test_entity_reference and field_test_entity_revision. field_test_entity_reference is of field type entity reference and field_test_entity_revision is of type entity reference revision. Both are referring to the same content type. I have created a node of this content type and its id is 7747. I am trying the below code and it sets value correctly for the field which is of type entity reference but not for entity revision version.


1 Answer 1


You need to store also the revision id, see Programmatically append multiple paragraphs to entity reference field on node.

Or simply set an entity, from which the field can get the data it needs in both cases:

$node->field_test_entity_reference->entity = $target_node;
$node->field_test_entity_revision->entity = $target_node;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.