submitting to the REST server with JSON, which includes an entityreference field, does not create the content on the new node.
Having done a raft of testing, it appears that the data is reaches services, but then does not get processed.
The JSON is:
{
"title":"Test Node Y",
"type":"element",
"body":{"und":[{"value":"Some text","format":"plain_text"}]},
"field_productentityref":{"und":[{"target_id":{"target_id":"[target_id:14480]","target_type":"node"}}]}
}Using http://drupal.org/node/1388924 as a reference for how to format the JSON to populate the entity reference.
Attached are watchdog entries associated with a query (based on the above). As you can see the data, including the entityreference is consistently there, but services is not putting this info into the entityreference field on the node create.
It could be that the query for field_productentityref is incorrect, but we have tried an exhaustive list of possible formats.
Is there a bug in there?
| Comment | File | Size | Author |
|---|---|---|---|
| node_resource_form_state.txt | 1.28 KB | gmak | |
| node_resource_create.txt | 930 bytes | gmak | |
| form_state.txt | 37.05 KB | gmak |
Comments
Comment #1
marcingy commentedMoving to support request because this is likely a case of the FAPI data structure being incorrect as services simply plugins into FAPI.
Comment #2
gmak commentedSome further testing may help to sort this one out.
If I execute the following php code:
A node is created, with a title, but again the entityreference field is not populated.
The data from the node_save operation shows:
Comment #3
mwidner commentedI can confirm this bug. I'm able to post properly formatted JSON with an entity reference; the system accepts the data, but doesn't populate the entity references in the new node.
Comment #4
azicchetti commentedIf your field is using the autocomplete widget, you just have to change the target_id format:
field_yourentityreference:{"und":[{"target_id":"anything (183)"}]}
The form handler probably gets (I've not checked yet in the code) the id with a regexp, but you must supply a fake title in order to work.
If the field is using another widget, say, the checkboxes, I think the target_id must be supplied in yet another way.
Comment #5
ygerasimov commentedServices do drupal_form_submit to the node form. So I propose you to debug the values in $form_state on normal form submission and build the same structure in your services call. @azicchetti has point about the autocomplete widget. I don't know which widget do you use.
Please reopen this issue if you still face these problems.