hello all,
i have a problem with restws. I explain me better.
I my drupal 7 install, I have created a new content type (named Pippo)
with title, body and a user reference field. Now, when i try to create
a new content of Pippo type with this json:
{"type":"pippo","title":"Pippo creato","status":1}
all works fine. Instead if i use this json:
{"type":"pippo","title":"Pippo creato","status":1,"field_ref_user":{"uri":"http:\/\/drupal7.local\/user\/4","id":"4","resource":"user"}}
restws responds with a 406 code. A json with compounds fields, like
user reference, must be created in some special way?
the user with id 4 exist.
Any help it's really appreciated
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | restws_uuid.patch | 11.31 KB | fago |
| #13 | 1355220-accept_output_format6.patch | 10.06 KB | sepgil |
| #11 | 1355220-accept_output_format5.patch | 9.3 KB | sepgil |
| #9 | 1355220-accept_output_format4.patch | 9.1 KB | sepgil |
| #7 | 1355220-accept_output_format3.patch | 9.14 KB | sepgil |
Comments
Comment #1
klausiUnfortunately RESTWS is currently not ready to import references to other resources like this. I know this is really ugly because RESTWS does not accept the format that comes from its own output. As a work-around you can experiment with passing in "4" as you would do it for any other field value.
Comment #2
klausiTagging, assigning to Sebastian.
Comment #3
sepgil commentedThis patch should fix the problem.
Comment #4
klausiInline comments missing. Please describe which case is covered in which branch.
"else if" should be one word, i.e. "elseif"
Description should eb on a new line. There should be an empty line before @param documentation. Also elsewhere.
entity_load_single() should not be necessary.
And we need new test cases for create/update with the reference array.
Comment #5
sepgil commentedI made a new patch, which uses the same functionality for create and update and therefore simplifies the code.
Comment #6
sepgil commentedComment #7
sepgil commentedHere a new patch that now works on the formating level, since the results of xml and json can be different. It isn't ready, since the new update test doesn't work correctly. But since I currently can't why, I figured that I could in the meantime post the patch so someone(klausi ? :P) could review it...
Comment #9
sepgil commentedAt last I've managed to fix the simpletest.
Comment #10
klausicomment please
needs to be on a new line
not a good variable name
mixed use of static and dynamic method xmlToarray()?
what is $res?
longer description what we do here please
Comment #11
sepgil commentedCorrected all issues mentioned above.
Comment #12
klausiI think that function should return FALSE if the type is not a reference to an entity. And add @return documentation for that.
The most important check here is entity_get_info(), so this should come first.
@param documentation would be helpful here.
The condition should be $id !== FALSE here, after you updated extractResourceId().
should be "a numeric array".
Should use the same FALSE condition as in JSON.
This could use a comment, that there is no URI and we use the standard XML to array converted data.
you should create the taxonmy terms first.
don't use 'und', use LANGUAGE_NONE instead.
This method is never used?
Comment #13
sepgil commentedI think all issues should be fixed now...
Comment #14
fagoMisses a new line before @param and after all @param statements. Also, I think it would be cleaner to use array $resource instead of $resourceArray.
Over at http://drupal.org/node/1682920#comment-6238976 I'd have called that variable array $reference, it's not really a resource, it's a reference to an resource.
same here, reference array would make more sense to me.
I really like seeing the data-normalizaition separated out more, that's really is what the "base-format" is about. Maybe we should even cleanly separate it out? See #1687836: Leverage Symfony serialization component ?
Comment #15
fagook, it turned out that #1682920: Add support for referencing entities by UUID can't be clearly separated out on top of this, so I've improved this one and incorporated the UUID bits here.
I've updated the patch by:
E.g. the following snipped works fine for setting a multiple term-reference field by UUIDs:
Comment #16
fagoNote: Currently getPropertyValues() ignores that existing properties. Probably we want to improve that to throw errors if not existing properties are set while ignoring read-only properties. But that's another issue, so I've not touched that.
Comment #17
klausiCommitted patch from #15, thanks!
I think it is ok to just ignore read-only properties right now. See also #1607662: Don't try to set non-metadata properties on update for unknown properties.