Setting Entity Reference Fields

Events happening in the community are now at Drupal community events on www.drupal.org.
dgtall's picture

I need to programaticaly set a value for a custom entity on a nodes entity reference field. I am trying to determine if all I need to do is just save the entity id or load the entity and use a metadata wrappper to set the value.

Comments

You only need to set the

darrick's picture

You only need to set the target_id. I.e.

$node->entity_reference_field['und'][0]['target_id'] = $entity_id;

Sacramento Area

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: