2

I have a Drupal 7 Services that my frontend call when I want to get (for example) all comments of node XYZ. All works, but I want to reduce informations that this call return (yes, from the backend). For example "hostname, mail, changed, registered_name, signature" are all data that I don't want to return back. Other example: if I call "user/X" service path it return "password, mail" and other informations that I consider private.

So, how can I intercept and remove this data before that service module send it back to the caller?

1
  • I believe the user retrieve resource only returns the password hash if the user requesting the data has the 'administer users' permission. Commented Jan 14, 2015 at 19:59

1 Answer 1

2

For user objects specifically there's hook_services_account_object_alter(), e.g.

function MYMODULE_services_account_object_alter($account) {
  unset($account->mail);
}

For other entity/resource types there's hook_services_request_postprocess_alter(), e.g.

function MYMODULE_services_request_postprocess_alter($controller, $args, &$result) {
  // Manipulate $result till your heart's content.
}
1
  • Thanks. To know which is the service that the external user has called I check "callback" entry of $result. Is there another more correct way ? $controller does not give me usefull informations.
    – ZioBudda
    Commented Jan 15, 2015 at 2:15

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.