I really like to have inline_entity_form and field_collection could be work together, so I write an integration module for this.
I found it will be saved a lot of codes, if a little change can be made on the inline_entity_form:
just change:

function inline_entity_form_field_attach_submit($parent_entity_type, $parent_entity, $form, &$form_state) {
    .....
    list($entity_id) = entity_extract_ids($entity_type, $item['entity']);
    $entity_ids[] = array($values['settings']['column'] => $entity_id);
   ....
}

to

function inline_entity_form_field_attach_submit($parent_entity_type, $parent_entity, $form, &$form_state) {
    .....
    list($entity_id, $vid, $anything) = entity_extract_ids($entity_type, $item['entity']);
   if(isset($values['settings']['columns'])){
      $entity_ids[] = array($values['settings']['columns']['id'] => $entity_id, $values['settings']['columns']['vid'] = $vid);
   }else {
      $entity_ids[] = array($values['settings']['column'] => $entity_id);
   }
   ....
}

, then, field collection will work happily with inline entity form, field collection user following code to insert a new field_collection_item:

/**
 * Implements hook_field_insert().
 */
function field_collection_field_insert($host_entity_type, $host_entity, $field, $instance, $langcode, &$items) {
  foreach ($items as &$item) {
    if (isset($item['entity'])) {
      if ($entity = field_collection_field_get_entity($item)) {
        if (!empty($entity->is_new)) {
          $entity->setHostEntity($host_entity_type, $host_entity, LANGUAGE_NONE, FALSE);
        }
        $entity->save(TRUE);
        $item = array(
          'value' => $entity->item_id,
          'revision_id' => $entity->revision_id,
        );
      }
    }
  }
}

Comments

sk2013’s picture

Thanks for sharing the code. However, we think if we could create an Inline entity form widget for field collection fields would be great.

Do you have any idea on how this could be achieved?

Thanks,

Sk2013

bojanz’s picture

Status: Active » Fixed

I'm not interested in adding field_collection specific hacks to the codebase. Thank you for sharing your solution.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.