Use $node = new StdClass(); to create the node through program. Or Example for creating node through program After node_save($node), You will get the 'nid' of created node
$nid = $node->nid;
Then again you load the created node from above nid
$node_loaded = node_load($node->nid); then create the field collection as,
>
$nid = $node->nid;
Then again you load the created node from above nid
$node_loaded = node_load($node->nid); then create the field collection as,
$node = new StdClass();
$node ->-----// node values.....
node_save($node);
nid = $node-nid;// after saving the new it will return the nid in $node->nid in Drupal 7
node_loaded = node_load($nid);
$field_collection_item = entity_create('field_collection_item',array('field_name' => 'field_event_conference'));
// fied_name in the node manage fields
$field_collection_item->setHostEntity('node',
$node_loaded);
$field_collection_item->field_fc_company[LANGUAGE_NONE]['0']['value'] = $company;
$field_collection_item->save();
Field collection contains another field collection.
$field_collection_item = entity_create('field_collection_item',array('field_name' => 'field_event_roadshow'));
$field_collection_item->setHostEntity('node', $node_loaded);
$field_collection_item->field_fc_company[LANGUAGE_NONE][0]['value'] = $company[0];
$field_collection_item->save();
$attendee_field_collection_item = entity_create('field_collection_item', array('field_name' => 'field_fc_management_attendees'));
$attendee_field_collection_item->setHostEntity('field_collection_item', $field_collection_item);
$attendee_field_collection_item->field_fc_mgmt_attendee_name[LANGUAGE_NONE][$k]['value'] = $manage[$k];
$attendee_field_collection_item->field_fc_mgmt_attendee_level[LANGUAGE_NONE][$k]['value'] = $level[$k];
$attendee_field_collection_item->save();
>
Comments
Post a Comment