Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. module_load_include('inc', 'entity', 'includes/entity.controller');
  2. global $user;
  3.  
  4. // Setup the values in the structure expected by the field_collection entity.
  5. $values = array(
  6. 'field_cnm_address_fname' => array(
  7. 'und' => array(array('value' => $address['fname'])),
  8. ),
  9. 'field_cnm_address_lname' => array(
  10. 'und' => array(array('value' => $address['lname'])),
  11. ),
  12. 'field_cnm_address_street1' => array(
  13. 'und' => array(array('value' => $address['street1'])),
  14. ),
  15. …etc.
  16. );
  17.  
  18. $entity = entity_create('field_collection_item', $values);
  19. $entity->setHostEntity('user', $user);
  20. $result = $entity->save();
  21.  
  22. //(field_collection.module, line 326)
  23. $entity->{$this->field_name}[$this->langcode][] = array('entity' => $this);
  24.  
  25. $entity->setHostEntity('user', $user);
  26.  
  27. global $user;
  28. $values = array();
  29. // I think you missing field name of field collection.
  30. $values['field_name'] = 'field_address'; // field collection name.
  31. $values['field_field_name'][LANGUAGE_NONE][0]['value'] = 'Mr';
  32. $values['field_last_name'][LANGUAGE_NONE][0]['value'] = 'D';
  33. $values['field_street'][LANGUAGE_NONE][0]['value'] = 'Vietnamese';
  34. $field_entity = entity_create('field_collection_item', $values);
  35. $field_entity->setHostEntity('user', $user);
  36. $field_entity->save();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement