I have a nested field collection item, field_collection_parent which contains one field_text and a field collection field_collection_child contains two text fields(field_a and field_b).

Now I'm trying to add more field_collection_child into an existing field_collection_parent (using its entity_id) but the new field_collection_child is not getting created.

Below are my codes:

$entityId = 331;

$field_collection_1 = entity_load('field_collection_item', array($remId));

$field_collection_2 = entity_create('field_collection_item', array('field_name' => 'field_collection_child'));
$field_collection_2->setHostEntity('field_collection_parent', $field_collection_1);
$field_collection_2->field_a['und'][0]['value'] = 'http://www.google.com';
$field_collection_2->field_b['und'][0]['value'] = 'http://www.google.com';

Even I've tried https://www.drupal.org/node/2382811, but no luck.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.