Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module_load_include('inc', 'entity', 'includes/entity.controller');
- global $user;
- // Setup the values in the structure expected by the field_collection entity.
- $values = array(
- 'field_cnm_address_fname' => array(
- 'und' => array(array('value' => $address['fname'])),
- ),
- 'field_cnm_address_lname' => array(
- 'und' => array(array('value' => $address['lname'])),
- ),
- 'field_cnm_address_street1' => array(
- 'und' => array(array('value' => $address['street1'])),
- ),
- …etc.
- );
- $entity = entity_create('field_collection_item', $values);
- $entity->setHostEntity('user', $user);
- $result = $entity->save();
- //(field_collection.module, line 326)
- $entity->{$this->field_name}[$this->langcode][] = array('entity' => $this);
- $entity->setHostEntity('user', $user);
- global $user;
- $values = array();
- // I think you missing field name of field collection.
- $values['field_name'] = 'field_address'; // field collection name.
- $values['field_field_name'][LANGUAGE_NONE][0]['value'] = 'Mr';
- $values['field_last_name'][LANGUAGE_NONE][0]['value'] = 'D';
- $values['field_street'][LANGUAGE_NONE][0]['value'] = 'Vietnamese';
- $field_entity = entity_create('field_collection_item', $values);
- $field_entity->setHostEntity('user', $user);
- $field_entity->save();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement