Skip to content

Instantly share code, notes, and snippets.

@grzegorznowak
Created October 1, 2013 16:48
Show Gist options
  • Save grzegorznowak/6781538 to your computer and use it in GitHub Desktop.
Save grzegorznowak/6781538 to your computer and use it in GitHub Desktop.
How to manipulate Drupal 7's fields, based on entity reference example. Minus validation, duplicates check, etc. Only the core logic. Please comment if you think it's substantially wrong.
$node = node_load($nid);
$node_wrapped = entity_metadata_wrapper('node', $node);
$references = $collection_node->[name_of_reference_field]->value();
// append new reference (note no sanity checks are included with this Gist)
$references[] = node_load($referenced_nid);
$collection_node->field_cards_reference->set($references);
$collection_node->save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment