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.
Make Comments Creation work with fields
I discovered that the comment creation can not handle it when you have comments with fields (in my case a file)
I reworked the way the comment creation works to a more drupal 7 way of problematically creating comments.
Comment | File | Size | Author |
---|---|---|---|
#3 | 2828798-refactored-comment-creation.patch | 1.16 KB | sysosmaster |
Comments
Comment #2
sysosmaster CreditAttribution: sysosmaster at 040lab commentedComment #3
sysosmaster CreditAttribution: sysosmaster at 040lab commentedComment #4
sysosmaster CreditAttribution: sysosmaster at 040lab commentedComment #5
tyler.frankenstein CreditAttribution: tyler.frankenstein commentedComment creation with fields does work, I've used it with many projects. Please share the code/structure you're using when trying to create a comment, as well as what core/contrib fields you are trying to use.
Thank you for the patch, and if we were ever to make a 7.x-4.x branch of Services, your approach would be used. It's unlikely we'll be able to accept that patch though for 7.x-3.x, because we've been using the "forms" approach for many years now.
Comment #6
sysosmaster CreditAttribution: sysosmaster at 040lab commentedit was not working for files (e.a. you upload a json for a comment service with as the JSON
{"Comment":{"nid":"1","cid":0,"pid":0,"uid":7,"language":"und","status":1,"subject":"Processing Result IfcOpenHouse.ifc","is_anonymous":0,"comment_body":{"und":[{"value":"{\"IfcApplication\": \"IfcOpenShell 0.5.0-dev\", \"IfcDoor\": {\"Total amount of IfcDoor elements\": 1}, \"IfcProjectGUID\": \"1234567890\", \"IfcWallStandardCase\": {\"Total amount of IfcWallStandardCase elements\": 4}, \"IfcWindow\": {\"Total amount of IfcWindow elements\": 5}}"}]},"field_result_file":{"und":[{"fid":"66","display":1}]}}}
I do this after I upload the file using the file endpoint.
I made the patch so other can use it allthough i totally agree to wait for the 7.x-4.x release for this approach (if we ever get one).
Comment #7
tyler.frankenstein CreditAttribution: tyler.frankenstein commentedYour JSON data looks fine, except for the "comment_body" value looks pretty strange.
P.S. Maybe try removing the "display" property from your file JSON object too.
Comment #8
sysosmaster CreditAttribution: sysosmaster at 040lab commentedAll of it works except for the field_result_file, that gets lost completely by the form handler somewhere (could not pinpoint it completely with my debugger). I suspect it is a similar problem as attaching files to node's. the form simply silently drops the file attaching.
Comment #9
tyler.frankenstein CreditAttribution: tyler.frankenstein commentedInteresting. In a case like this, I'm starting to think that a contrib/custom module on your site may be "form altering" that particular field during Services calls. Do you see any potential suspects in your module list?
Otherwise I'm very certain that attaching file ids to nodes and comments is working properly, I use both currently in a few different apps. This patch may be useful to: #2224803: Possible patch for multi-value fields
Comment #10
kylebrowning CreditAttribution: kylebrowning as a volunteer and at Acquia commentedYeah we use form submit to get all the benefits of the hook system, this is a wont fix.