Slightly changed description to fit more of my append/insert issue.
$thisUser = entity_load('user', array($user->uid));
$thisUser = $thisUser[$user->uid]; //make thisUser the user object, not an array of user objects
$newFieldCollectionItem = array();
$newFieldCollectionItem['field_name'] = 'field_download';
$newFieldCollectionItem['field_download_filename'][LANGUAGE_NONE][0]['value'] = $src;
$newFieldCollectionItem['field_download_date'][LANGUAGE_NONE][0]['value'] = time();
$newFieldCollection = entity_create('field_collection_item', $newFieldCollectionItem);
$newFieldCollection->setHostEntity('user', $thisUser);
$newFieldCollection->save();
Line 2 $thisUser[$user->uid] is what made it work for me.
The rest of the code had been the exact same, but adding line 2 is what did it for me!!!
Discover a detailed Suzuki Spare Parts Catalog at BP Auto Spares India. We offer clear product descriptions, diagrams, and part numbers to help you find exactly what your vehicle requires. Quality, compatibility, and trust—all in one place.
ReplyDelete