Closed (fixed)
Project:
RESTful Web Services
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
2 Jan 2013 at 16:29 UTC
Updated:
16 Jan 2013 at 20:00 UTC
Jump to comment: Most recent file
Comments
Comment #1
wwhurley commentedMight help if I actually attach the patch file.
Comment #2
wwhurley commentedComment #3
klausiYes, this sounds like a good idea. Ideally this drupal_alter() call should be done in restws_handle_request() between a call to normalization and serialization. Unfortunately serialization and normalization is very interwoven in RESTWS, so I don't think it makes sense to try and split that up at this point (something for RESTWS 3.x since that would also mean an interface change). So we have to add this alter invocation to all format operation methods :-(. Very ugly, but that would be fine with me.
In Drupal 8 we use the Symfony Serializer component for REST module, which makes a lot more sense.
Should be "Alter the outgoing response values", since you don't want to alter the serialized string but the data structure. And there is a trailing white space.
Add an example by setting a value in $response.
You forgot the delete operation and the operations of the XML and RDF formats.
Comment #4
wwhurley commentedAdded the alter hooks to XML and RDF and changed the signature of the alter hook to also have the format name since the response is mixed. Added alter hook to update and delete in case they want to return anything beyond the default empty array. This came about from wanting to send additional information back from the resource, but since only specific functions are called on the resource it wasn't possible. There is an annoying amount of repetition involved, but I'm unsure of a better way of doing it. Attached is the revised patch.
Comment #5
klausiThe type hinting to an array for $response is wrong, since that could also be an object (e.g. for the XML use case).
We can omit that line. Just pass in __FUNCTION__ directly to drupal_alter().
according to the drupal_alter() docs the second parameter should be the alterable thing, and the rest should be context variables. $values and $function should be swapped.
Yes, this approach is repetitive and ugly, but as I said, from the current architecture we cannot do it differently.
Comment #6
wwhurley commentedHah, silly me, I changed the PHP doc block but didn't change the function signature. I've changed the alter signature to move the response forward in the call. We can't pass __FUNCTION__ to drupal_alter because only variables can be passed by reference and PHP gives a nice big error when I tried that.
And again, patch attached.
Comment #7
wwhurley commentedComment #8
klausiTweaked the comments a bit and committed this. Thanks!