Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Here's my patch possibly solving the support-feature I posted earlier
As I already mentioned in the original post, the patch is straight forward and I am not sure if it suffices the php/Drupal coding standards (I am not a php programmer). However it works for me...
Please review.
Florian
Comment | File | Size | Author |
---|---|---|---|
#78 | services-multivalue_fields_fix-2224803-78.patch | 1.63 KB | stupiddingo |
Comments
Comment #1
flier CreditAttribution: flier commentedComment #3
flier CreditAttribution: flier commentedNew patch, this time I read the Drupal FAQs about patching. Sorry for that.
Comment #4
flier CreditAttribution: flier commentedComment #5
flier CreditAttribution: flier commentedComment #6
marcingy CreditAttribution: marcingy commentedComment #7
marcingy CreditAttribution: marcingy commentedThe patch needs brought upto drupal coding standards see https://drupal.org/coding-standards
Also
This should be LANGUAGE_NONE instead of und in this case, but a more significant issue is that the patch won't work with sites that have translations enabled.
Comment #8
marcingy CreditAttribution: marcingy commentedComment #9
flier CreditAttribution: flier commentedThe language issue could be solved by, i.e,
However, I also ran into this problem when updating a node, I basically used the same method
as proposed in my patch. If someone is willing to make the new patch coding standards compatible...
I will share it, of course.
Comment #10
mzgajner CreditAttribution: mzgajner commentedIn case this helps anyone:
I had the same issue with multi-value fields. It appeared when upgrading from 3.5 to 3.7. I tried the patch from this thread, which worked (multi value fields worked again), but it broke some other things.
The node being created with Services did not respect the default value of a specific taxonomy field that was set on the content type. I do not pass any value for this field when I do the post and without the patch, the general default value was used. With the patch, no value is passed and stored. My site has translations enabled, so it might have something to do with it.
For now, I reverted to 3.5 where everything works.
Comment #11
mccrodp CreditAttribution: mccrodp commentedHi,
Thank you for your post Matek. I am using Drupal 7.27 and Services 3.7 to upload a JSON node via CURL referencing existing files within Drupal. It was not working as explained in this issue. I applied the patch and it was still not working still not working.
I then downgraded to Services 3.5 without applying the patch and it worked. I have since tested Services 3.6, 3.7 and current dev without the patch, and none of them work.
Did something break between 3.5 and 3.6?
I will stick with 3.5 for the moment as both file and image are working for me.
Thank you.
Comment #12
mnshantz CreditAttribution: mnshantz commentedWhen we went from Services 3.5 to 3.7 we also had an issue with it not working. I was able to trace it back to commit 0e39f46, specifically when this was added:
$stub_node = (object) array_intersect_key($node, array_flip(array('type', 'language')));
$stub_node->name = $user->name;
drupal_form_submit($node_type . '_node_form', $form_state, (object)$stub_node);
And this removed:
drupal_form_submit($node_type . '_node_form', $form_state, (object)$node);
By reverting back to the "non" stub_node everything began working the same way it did.
Comment #13
streiten CreditAttribution: streiten commentedSame issue here. (drupal 7.26 / services 3.7)
I am trying to populate a unlimited multi-value field with color field module/widget (https://drupal.org/project/color_field) for existing nodes by means of a cURL PUT request.
$data_string = '{ "field_colors": { "und":[ { "rgb":"#AAAFFF" },{ "rgb":"#000111" },{ "rgb":"#FBFBFB" } ] }}';
neither the patch nor #12 work!
if the fields are already there updating works as expected.
issuing the request repeatedly seems to add the fields though.
so i guess i am stuck PUTing in a loop for now.
Comment #14
Atomox CreditAttribution: Atomox commentedThis is just a guess, but I know when AJAX adding fields are in the picture, Drupal checks the form array to confirm that if a value was passed, the field existed beforehand. This is a security measure, which keeps AJAX from inserting malicious data that was not expected by Drupal. I'm seeing this issue via services. Only the first field in any given taxonomy term (unlimited field) is added via node create. It doesn't matter which valid value is passed, it only adds the first one.
This would explain why bzoo (in #13) is only seeing updates work when the fields already exist. I'll bet all the money in my pockets that if bzoo tries editing his node, and adding 2 more fields, that only the first (if any) new field will be added.
Again, this will occur when you have unlimited selected, but only allow 1 tag/reference/etc per field. This should not happen for multi-select fields, or free tagging.
Watching this one, as I suspect this is a problem with implementing using the Form API. I'm hoping I'm wrong, as I'd love to see a simple fix.
Comment #15
marcingy CreditAttribution: marcingy commentedSee #1985390: Problems with multi-valued fields and [#1066786]
Comment #16
zarexogre CreditAttribution: zarexogre commented#3 worked a treat thanks for this
Comment #17
kylebrowning CreditAttribution: kylebrowning commentedThis is needs work as it needs tests, but would love to see this in Services to help the ailment of adding values to multi-value fields.
Comment #18
mrfelton CreditAttribution: mrfelton commentedHere is a tidied up patch based on #3 that also enables support for multivalue fields on the user resource.
Comment #19
marcingy CreditAttribution: marcingy commentedThis code hunk is repeated
Lets move it into a function that can be called. Also
needs spaces round = to meet code standards
Extra white space here
And missing newline at end of file.
Comment #20
ParisLiakos CreditAttribution: ParisLiakos commented#18 works for me for multiple entityreference fields, thanks
Comment #21
daekano CreditAttribution: daekano commentedSame problem as #13. We have a high volume site, looping PUTs is simply not an OPTION (heh).
Is this being represented as an issue with the Form API?
Comment #22
cudevdev CreditAttribution: cudevdev commentedThe documentation should include some information on how to submit a multivalue field.
Comment #27
rynebl CreditAttribution: rynebl commentedSimilar code should also be applied to the update function, as it is has the same issue as create node, hopefully this helps others trying to solve this.
Comment #30
firoz2456 CreditAttribution: firoz2456 commentedI am using Drupal 7.37 and Services 3.12. Patch #3 and Patch #18 is not working for me. But downgrading services version from 3.12 to 3.5 is working fine. @mzgajner thanks for your comment.
Comment #31
Shiraz DindarNot sure on what the status of the patch is in #18. We simply applied the patch from #12 which undoes what was done in 3.6 and multivals work fine again. Perhaps someone can confirm that #12 is safe. I am unclear on the purpose of the stub node.
Comment #32
pebosi CreditAttribution: pebosi as a volunteer commentedRemoving
and changing this
to
works for me...
Comment #33
Psycle Interactive CreditAttribution: Psycle Interactive commentedWondering on the state of this issue, as currently any field that is defined to allow an unlimited number of values does not work when creating/editing a node through the services module.
For example:
I have a field called 'subpages', this is configured as:
Field type - Text
Widget - Text field
Number of values - unlimited
When i try to create a now with this field through services, it only saves the first value and ignores any others set, even though the field is defined as unlimited.
I am sending the following for the subpages field in the post data:
field_subpages[und][0][value]=value1&field_subpages[und][1][value]=value2&field_subpages[und][2][value]=value3
Comment #34
briantes CreditAttribution: briantes as a volunteer commentedI have the same issue. I have applied the patch #18 and the suggestion from pebosi, but I doesn't work.
I can't populate a field with an unlimited values allowed.
I have 3.12 version. Then, must I downgrade to 3.5 in order to get it working? There is a lot of fixed bugs and improvement from 3.5 to 3.12 and I want it.
Is there any other patch or solution? Thanks
Comment #35
Psycle Interactive CreditAttribution: Psycle Interactive commentedI have created the following patch against the 7.x-3.x branch, which also works on the 7.x-3.12 release. This fixed the issue i was having with unlimited multivalue fields not saving more than 1 value when creating nodes. The update node action still works and i have tested adding more values and removing values.
I hope this will prompt the fix to be rolled into a future release.
Comment #36
kylebrowning CreditAttribution: kylebrowning as a volunteer commentedComment #37
gkucsko CreditAttribution: gkucsko commentedJust tested #35. It seems like it indeed works, such that you can now create an additional entry in the file field array. However it is still limited to 1 new entry per request.
Comment #38
Psycle Interactive CreditAttribution: Psycle Interactive commented@gkucsko
Just to clarify what you are saying, is there still an issue with File/Image field types that are defined as unlimited/multiple? If so, i will try to replicate and see if i can fix it.
Comment #39
gkucsko CreditAttribution: gkucsko commentedyes, though it seems to be a general issue with the service module that you can only add one item at a time to a multi-valued field (probably related to drupal form management). see also here: https://www.drupal.org/node/1985390
Comment #40
peterlolty CreditAttribution: peterlolty as a volunteer 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_value
With 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_value
And 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!
Comment #41
Anonymous (not verified) CreditAttribution: Anonymous commentedUnfortunately none of the patches have allowed my to upload more than file to a multi-value field. Not only for unlimited cardinality, but even for fields with values between 2-10 as well. Only one file is saved, delta 0, overwriting what was there before. Other files after the first in the JSON data object sent to the resource are ignored.
Where is there any documentation regarding how to upload files to multi-value fields with Services? peterlolty's method doesn't work since I am using JSON, not URL encoding.
Comment #42
kylebrowning CreditAttribution: kylebrowning as a volunteer commented#32 seems to be the official way.
Comment #43
Anonymous (not verified) CreditAttribution: Anonymous commentedTried that, couldn't get it to work for a multi-value image field on a node. Discovered the targeted action allowing file attachments directly to nodes. I got that to work after a lot of wrangling trying to get AngularJS to get the data in the right format for multipart/form-data Content-Type. It would have been so much easier if this targeted action accepted base64 data & Content-Type: application/json. Anyway, I never got this to work, so I can't contribute anything. Hopefully somehow this gets sorted out.
Comment #44
peterlolty CreditAttribution: peterlolty as a volunteer commentedI also tried it on JSON, doesnt work.
But if you are using URL encoding as the request content type, you can try my posted method as I am currently using this.
Comment #45
norbertwolfgraf CreditAttribution: norbertwolfgraf commented#32, #35 worked like a charm. Thank you so much. Works on services 7.x-3.13 for 'number of values' set to unlimited and 1-10.
Comment #46
jerrac CreditAttribution: jerrac commented#35 seems to have worked for me on 3.14.
Comment #47
hanoii#35 worked for me for adding, but I cannot figure out how to remove an item, @PsycleInteractive, you mentioned removal works, how do you do that?
Comment #48
hanoiiNow that I tried better, I got to remove a field collection items by setting all of the values as blank, however, a PUT (update) doesn't seem to create new elements of the multiple valued field collection, creates the first one. I attempted a similar fix without success.
Comment #49
Chipie CreditAttribution: Chipie commentedAfter applying patch #35 the nodes created by services are unpublished by default. Anyone knows why?
Comment #50
Chipie CreditAttribution: Chipie commented#35 can't be applied to 7.x-3.15.
Comment #51
Chipie CreditAttribution: Chipie commented#35 does not consider the default settings of the contenttype (e.g. status, promote, sticky), so I have modified it for 7.x-3.14.
Comment #52
Chipie CreditAttribution: Chipie commentedHere is a version for 7.x-3.15
Comment #53
marcingy CreditAttribution: marcingy commentedBefore we can even think about committing this it needs tests
Comment #54
marcingy CreditAttribution: marcingy commentedComment #55
jomarocas CreditAttribution: jomarocas as a volunteer commentedThe patch attach need review
Comment #56
tyler.frankenstein CreditAttribution: tyler.frankenstein commentedjomarocas, I think marcingy meant it needs work because tests need to be written and then re-rolled into patch.
Comment #57
poldown CreditAttribution: poldown as a volunteer commentedSame issue for update. The same logic as in #52 (for
_node_resource_create
) needs to be added to_node_resource_update
:Comment #58
tyler.frankenstein CreditAttribution: tyler.frankenstein commentedThis patch addresses #57 by also adding multi value support when updating nodes. We'll still need to add this similar behavior to the other core entity types (users, comments, vocabularies, terms) and add tests.
Comment #59
tyler.frankenstein CreditAttribution: tyler.frankenstein commentedThis patch adds additional support for multi value fields during user update. I briefly tried adding support for multi value fields during user creation, but as far as I can tell it isn't quite as straightforward as the technique we used with node creation multi values.
Comment #60
stupiddingo CreditAttribution: stupiddingo as a volunteer commentedTested patch #59. It applies cleanly and handles multiple value unlimited text fields and double fields correctly for node create, node edit and user update.
Given the coversation above and lack of full resource coverage I'm hesitant to mark RTBC so I'll going to leave the status unchanged.
That being said, this patch resolved a major bug and a huge thanks to y'all for chasing this down with a clean simple fix. I spent a couple days totally going the wrong direction...
/me hat tip
Comment #61
jerrac CreditAttribution: jerrac commented#59 works for me as well.
What, exactly, is left to do before it can be merged?
Comment #62
kylebrowning CreditAttribution: kylebrowning as a volunteer commentedPer #59, this doesn't work on user entities yet, and may possible break user creation.
Tests are needed before we commit
Comment #63
Erhvervswebdesign CreditAttribution: Erhvervswebdesign commentedPatch #59 works well for me. By patching we are now able to upload multiple images through services.
Any idea, if or when there will be an update for the services module including the feature?
Comment #64
kylebrowning CreditAttribution: kylebrowning as a volunteer commented@Erhvervswebdesign see #69 and #62
Comment #65
khiminrm CreditAttribution: khiminrm commented@tyler.frankenstein, thanks for your patch in #59!
It works well for me for updating multi value text field in users. I used this patch with services 7.x-3.19.
Comment #66
xpersonas CreditAttribution: xpersonas commented@tyler.frankenstein - Thank... you. Saved my sanity.
Patch in #59 works for me using Services 7.x-3.20.
Worked out the issue I had with multi-value image fields.
Comment #67
Jeff Veit CreditAttribution: Jeff Veit commentedIt took most of a day to find this problem, and this patch. Non-intuitive because it was on a text field. Patch in 59 applies cleanly to the current services (7.x-3.20) and works.
Comment #68
Jeff Veit CreditAttribution: Jeff Veit commentedReviewing the code. Will comment later.
Comment #69
sangas CreditAttribution: sangas commentedThis patch not work for me
Console error
Comment #70
tyler.frankenstein CreditAttribution: tyler.frankenstein commented@sangas The patch is separate from the issue you are experiencing, you are sending bogus data up to the field, you need to adjust the widget in Drupal and then adjust the JSON delivery to match.
Comment #71
tyler.frankenstein CreditAttribution: tyler.frankenstein commentedRestoring important info provided by @Jeff Veit:
Thank you Jeff for this info, it's interesting to hear that particular line may not in fact be needed at all. As far as the mitigation, from my understanding it would be safe because everything still runs through the drupal form submit layer, and all validation should be picked up that way. It'd be great to hear other opinions on that matter, as well as comments about the array_merge() call.
Comment #72
Jeff Veit CreditAttribution: Jeff Veit commentedI tried some simple exploits without success, but I reckon to what you want is some code in node_submit which takes the input and decides that it's not ok, and discards it in favour of the existing value. If that happens, then the value in $old_node is our exploit data. And I reckon the best chance of that is data which is malformed in some way, which is why I first tried sending an array to a text field.
I think the patch should avoid mixing clean and dirty data. Validate the data before it's merged if the merge is necessary. (And I'm not sure it is.) That way the submit function and the merged data match and the situation described above can't occur.
All this applies to the other clean/dirty merges too.
Comment #73
sangas CreditAttribution: sangas commentedThe drupalgap generates this json code for unlimited fields
field_tip_obiavlenia1":{"und":{"value":["1","2",""]}}}
But the correct query
field_tip_obiavlenia1":{"und":[{"value":"1"},{"value":"2"}]}
Comment #74
alexmoreno CreditAttribution: alexmoreno at Acquia commentedused the patch for services 3.20 after it was running me crazy with this issue. Works like a dream, thank you!!!!
Comment #75
karaoglanoglou CreditAttribution: karaoglanoglou commentedJust logged in to say that patch #59 works like a charm for a multivalued link field in Services 3.20.
You saved me tons of work, thank you!
Comment #76
skylord CreditAttribution: skylord commented#59 applies nicely on 3.21. Working OK - thanks!
Wonder - will this issue still be not RTBC after 3-years anniversary of that patch in august? :-)
Comment #77
alexmoreno CreditAttribution: alexmoreno at Acquia commentedComment #78
stupiddingo CreditAttribution: stupiddingo as a volunteer commentedRe-roll of #59. Only line numbers change.
Comment #79
tyler.frankenstein CreditAttribution: tyler.frankenstein commentedThank you for the re-roll in #78, I am now hiding #59.
Comment #80
avanish12 CreditAttribution: avanish12 commentedHello All,
I am still not able to add multiple image during node update. I am getting error : 500 Service unavailable (with message).
No message print on error log and watchdog.Please help on it.
Thanks in advance !!
Comment #81
sano CreditAttribution: sano commentedThe patch solved my problem on the services 7.x-3.24 version. Thank you.
Comment #82
ireferpesa CreditAttribution: ireferpesa commentedHello,
I have version 3.27 and can't add files that are multiple values.
field_image works because you can only upload one image. field_gallery and field_download do not work
{
"type": "press_area_notes",
"title": "prueba v1",
"body": {
"und": [{
"value": "test body!"
}]
},
"language" : "es",
"field_image": {
"und": [{
"fid": "2228"
}]
},
"field_download":{
"und": [{
"fid": "2469"
}]
},
"field_gallery":{
"und": [
{"fid": "2223"},
{"fid": "2229"}
]
}
}