Sorry to open up another ticket on a similar subject, but I've posed questions on stack overflow, the forums, and no one seems to know the answer to my questions. Basically I'm trying to alter the output of a field before it is delivered to my service. So far I have tried, field templates (which aren't used for services). as well as theme_preprocess_views_view_fields, which again, is never used because it the theme is never rendered. Is there a function to alter the output of the field before it goes to the services view ?
Comments
Comment #1
dippers commentedDo you actually mean before the 'services view' (before the view is built and rendered) or do you mean before the output is sent from the endpoint (after the view is rendered)? The latter can be done using:
and the modify the result array.
Comment #2
cdmo commentedThanks, I didn't ask this question, but I did have the same one and that function helped me alter the json output of a service.
I wonder, is this hook (or any other Services Views hooks) documented anywhere?
version: 7.x-1.0-beta2
Comment #3
ygerasimov commentedI have added basic documentation about hook_services_request_preprocess_alter() and hook_services_request_postprocess_alter() hooks to Services module.
Comment #4
cdmo commentedThank you very much!
Comment #5
dereckd commentedThis does seem to address the output of altering the view it's self, but I'm interested in altering the output of the field only. For instance, no matter how I attempt to format things, the user image is always output as a url in HTML .... I would like to strip the html before the services output.
Comment #6
dippers commentedThe way I got around this was to write a custom field formatter to output raw urls. You could also do it using views-php of a display suite custom field but they will all require some php knowledge.
Comment #7
dippers commentedThe following will give you a custom field formatter for images and cropped images.
Comment #8
dereckd commentedThat is exactly what I was looking for, for my use case I ended up using a very simple approach to the formatter
I'm still a bit confused about the #markup portion of the array, but none the less it works exactly like I wanted
Thanks
Comment #10
DrCord commentedI was dealing with an issue with IP addresses not being converted from long to an actual IP, the hook_services_request_postprocess_alter hook helped!
Here's the code: