Error messageException: The host entity may be set only during creation of a field-collection item. in
FieldCollectionItemEntity->setHostEntity() (line 191 of /home/quickstart/websites/s7.dev/sites/all/modules/field_collection/field_collection.module

Comments

chriscalip’s picture

Version: 7.x-1.0-beta1 » 7.x-1.x-dev
thebuckst0p’s picture

Same issue. Any ideas?

munkyonline’s picture

Looks like the same issue described here: http://drupal.org/node/1205670 and http://drupal.org/node/1197094

faktor’s picture

I know it isn't clear solution, but I just apply comment to an exception on line 191 - field_collection.module. Maybe I find some errors I caused. But looks like it works now.

fago’s picture

I've committed a fix, please try the next dev snapshot.

Anonymous’s picture

Well... it avoids the error message but it keeps emptying my form collection after the submit in the administration page. I created the field collection in a user form, so the user type his information in the registration form, everything is perfect until the administrator submit the form after setting the account in active.

I don't really know what it is about, cause the information are not remove from the database, just from the form.

Thanks for the commit by the way, do you think it's because I use it in the user form ? Do I am the only one in this case ?

kugta’s picture

The error message disappeared indeed. But instead the form breaks after submiting (blank page) in my case. I don't find any error messages in the server error log.

While the "error message" problem appeared only after editing the node, the page break is appearing after node creation as well.

Anonymous’s picture

Ok guys I think I got it, the presave function seems to erase the whole items in the form instead of putting the 'value' key only. As I'm not very used to git I will just post the code here :

function field_collection_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
foreach ($items as &$item) {
// In case the entity has been loaded / created, save it and set the id.
if (isset($item['entity'])) {
if (!empty($item['entity']->is_new)) {
$item['entity']->setHostEntity($entity_type, $entity, LANGUAGE_NONE, FALSE);
}
$item['entity']->save(TRUE);
$item['value'] = $item['entity']->item_id;
}
}
}

In my case it works, tell me about you !

stevector’s picture

I found these errors went away when I updated both Field Collection and Entity to the latest in the dev branches.

mariagwyn’s picture

ditto on #9.

kugta’s picture

I also found that the error is disappeared, but I had this issue simultaneously http://drupal.org/node/1187010 so I couldn't see it working. Thanks for the update.

fago’s picture

Status: Active » Fixed

Ops, that's already fixed - see #5.

Status: Fixed » Closed (fixed)

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