Closed (won't fix)
Project:
Services
Version:
7.x-3.0
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
2 May 2013 at 18:01 UTC
Updated:
7 Jan 2016 at 01:16 UTC
Jump to comment: Most recent
Hello guys!
I'm writing a custom module to deploy content from 2 Drupal sites and we're using Services for that.
Everything works fine except for multi-valued fields:
Only the first field is being deployed to the destination site. If I want all fields deployed, I have to manually add another field until the number of items match.
Does anyone know why this happen and a way do make it work for fields with multiple values? Is this a bug in the module?
Thanks!
Comments
Comment #1
marcingy commentedServices just calls drupal_submit so the issue is likely with your data structure.
Comment #2
jmoreira commented@marcingy I thought that as well at first, but the structure seems correct for what I've seen in some documentations. And it does work when the number of items match.
For example: if I have the field Test at one server and add 3 values to it, only the first will be copied to the other server. If I deploy again, the second value goes, and so on. I think the module only gets the form like you would when you open it and doesn't emulate the "Add Another Item" behavior.
So it does work, as long as there's the same number of fields in both servers, but I need it to create the extra fields as well.
Let me know if I didn't explained it very clearly.
Comment #3
marcingy commentedSo I did a quick google and came up with http://drupal.org/node/1066786, so it seems like you are correct about the ajax part, and it is actually a core bug. You might be able to define a hook_form_alter to increment the field item count in question?
Comment #4
jmoreira commentedYes, I'm doing something similar to that and it works for one-level fields. But I have multi-valued fields inside of field collections, so it's being kind of tough to work on an algorithm for that. But if it's a core bug, I guess I don't have another choice, right?
Comment #5
jmoreira commentedComment #6
marcingy commentedThis is won't fix for services.
Comment #7
yogesh1110 commentedHi, I am stuck up simillar kind of situation. I have field colletion with multiple value and I am not able to submit 2 value through service API. Can you please let me know how you overcome your problem?
Comment #8
flier commentedHi!
Any1 found a solution for this one? I am currently also stuck with that.
Comment #9
Atomox commentedHey guys, as I commented over at: https://www.drupal.org/node/2224803#comment-8986421, after looking at the code, I believe this is an implementation issue in services, and not a core bug. This is explicit security to protect ajax-enabled form elements, and prevent altering of the form state between ajax calls. It's unfortunate that this gets in the way of the otherwise good idea for form api validation in services. However, this is a pretty large bug.
Is there anything we can do to fix it, aside from overriding the implemented callbacks, and writing custom handlers?
Comment #10
marcingy commentedIt is not an implementation issue with services it is an implementation problem with how unlimited value fields behave in drupal core and the fact that is an interaction via AJAX that causes a form rebuild and hence the appending of additional (n) elements. If n is fixed then there is no issue as the form elements exist for drupal_form_submit when it generates the form.
At the end of the day services is simply a wrapper to drupal_form_submit.
You need to create custom handlers to simulate what the form build operation does. However if anyone can come up with a working generic solution we can look to add it to services but you really need to read #1066786: How to add multiple Link-field entries programmatically using drupal_form_submit? to understand the issue.
Comment #11
peterlolty commentedI use Services Entity API module to deal with the multi-valued field, no extra code/hook is added, it works in native,
I think the correct format of the POST data is the key of getting it done.
For example, I have a entity reference field which is multi-value (set to unlimited)
what i need to POST the data are as follows,
NOT Url encoded
any_thing_else_key=any_thing_else_value&borrow_record_multiple[0]=5284&borrow_record_multiple[1]=5283&any_thing_else_key=any_thing_else_valueWith Url encoded
any_thing_else_key=any_thing_else_value&borrow_record_multiple%5B0%5D=5284&borrow_record_multiple%5B1%5D=5283&any_thing_else_key=any_thing_else_valueAnd the C# code are as follows
And the result are as follows
However, I am dealing with my custom entity, not node, so you may try entity_node instead of node after Services Entity API installed.
Version I am using,
Services 7.x-3.12
Services Entity API 7.x-2.0-alpha8
Cheers!