0

I'm trying to create the field collection item using Services field collection module and attach new field collection item to the current user.

function _services_fc_create($field_collection) {

  $field_collection = _services_arg_value($field_collection, 'field_collection');
  $field_collection = (object) $field_collection;

  $field_collection->revision_id = NULL;

  entity_save('field_collection_item', $field_collection);

  return $field_collection;
}

The code above creates field collection but does not set host (like setHostEntity).

Please note, that delete function is deleting the host record without issues.

function _services_fc_delete($fcid) {

  entity_delete('field_collection_item', $fcid);

  return TRUE;
}

Here is my POST data:

{
    "bundle":"user",
    "field_name":"field_cost_ref",
      "field_date_cost": {
    "und": [
      {
        "value": {
          "date": "1554328800"
        }
      }
    ]
  },
  "field_amount": {
    "und": [
      {
        "value": "10"
      }
    ]
  },
  "field_details": {
    "und": [
      {
        "value": "tessdsdt"
      }
    ]
    }
}
  • Is this Drupal 7? – Kevin Jan 7 at 20:49
  • @Kevin Yes indeed – adpo Jan 7 at 21:02
  • Where are you attaching host entity id info? – Kevin Jan 7 at 21:03
  • @Kevin I tried in the JSON with no luck (or maybe I don't know how to debug). PS. I can modify the module for needs. – adpo Jan 7 at 21:06
  • Related issue on d.o: Field Collection + Services. – leymannx Jan 7 at 21:58

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.