3

Are there any hooks to alter the Services modules output. For eg : If I get a result like this for a file object.

{
  "fid": "132",
  "uri": "public:\/\/512dab4918036.jpg",
  "filename": "512dab4918036.jpg",
  "filemime": "image\/jpeg",
  "uid": "1",
  "status": 1,
  "timestamp": 1361947464,
  "filesize": 2521,
}

I want to limit it for users with certain roles.

I am looking for this as I have made many services resource manually so I don't want to edit them all and simply use the output alter hook to do something.

Is it possible ?

2
  • What exactly do you want to do ? Remove some of the fields in the file object ?
    – drcelus
    Commented Feb 27, 2013 at 13:45
  • @drcelus no i want to deliver a default output if user dont met certain criteria.
    – niksmac
    Commented Feb 27, 2013 at 14:13

1 Answer 1

4

The available hooks for Services are documented in the api docs for services

You probably want hook_services_request_postprocess_alter($controller, $args, $result); which allows you to change the array of $result any way you want.

2
  • may i know how to use "hook_services_request_postprocess_alter" .I have field called 'body' in $result ,I want to wrap it with CDATA.Any idea how to do it? &$result[0]->body is my variable
    – rks
    Commented Mar 21, 2016 at 11:31
  • I assume you mean you don't know how to implement a hook? If you have a module named mymodule, you would implement a function called mymodule_services_request_postprocess_alter() with the arguments described above. More on Drupal's (pretty weird) hook system is at drupal.org/node/292
    – rfay
    Commented Mar 23, 2016 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.