I have a node form, with an entity reference field.
I'm trying to hide the reference field from the node form and automatically reference an entity created by the node author.
Im using code like the following to fetch the entity to be referenced.
$query = new EntityFieldQuery();
global $user;
$query->entityCondition('entity_type', 'node_ref');
$query->fieldCondition('cmp_ref', 'target_id', $user->uid);
$result = $query->execute();
$storeids = array();
foreach ($result as $ref) {
foreach ($ref as $ref_id){
$refids[] = $ref_id->id;
}
}
$entity = entity_load('node_ref',$refids);
foreach ($entity as $ref) {
$ref_id = $ref->id;
}
return $ref_id;
I think its a long way of doing it but I just modified some code I found in a module.
Now upon save of the node I would like the entity reference field to reference $ref_id
So something like
$node->entity_reference_field[$node->language][]['target_id'] = $ref_id;
How do I call this on node submit? If I unset the field on the node form will the value still be set?
Thanks for any help