Is there a way to create a field collection programmatically? I saw this code:
$field_collection_item = entity_create('field_collection_item', array('field_name' =>'field_text')); // Create new field collection item. $field_collection_item->setHostEntity('node', $node); // This is required, there shuold be a host entity, this case I used a node. $field_collection_item->field_text[LANGUAGE_NONE][0]['value'] = 'Test Value'; $field_collection_item->save(); // Save the field collection item.
But when I run this code I get this error:
Exception: Invalid field name given: field_text is not a Field Collection field.
I can’t find a proper solution for this.