1

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.

$node-field_test_entity_reference->target_id=7747;
$node-field_test_entity_revision->target_id=7747;
$node->save();
2

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;
$node->save();

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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