According to the Services API in Drupal 7, we can use hook_services_request_postprocess_alter() to alter drupal’s REST response before returning it to the user. This is useful if you want to alter the structure of an array, or strip out data we don’t want returned to the API user. However, I don’t see any way to identify what resource is being requested explicitly.
The Hooks passes: ($controller, $args, &$result);
The controller has semi-identifiable information, such as the callback which was fired, or the file where this resource exists. For instance, when firing a node INDEX request, we’d see:
[help] => List all nodes [file] => Array ( [type] => inc [module] => services [name] => resources/node_resource ) [callback] => _node_resource_index [args] => Array ( [0] => Array ( [name] => page [optional] => 1 [type] => int [description] => The zero-based index of the page to get, defaults to 0. [default value] => 0 [source] => Array ( [param] => page ) )
Etc. However, there is nothing standard here across services which would tell us: “This is a node INDEX request, using the NODE endpoint.”
To be clear, we’re referring to node in the resource sense, such as my_host/my_endpoint/node.json. Meaning, which of our endpoint’s resources is being requested here, and what (if any) method/operation are we performing.
I was hoping there was something standard within this hook to identify this information, as opposed to relying on more external data, such as the GET or POST variables.
Anyone have insight into this?
[edit]:
hook_services_request_preprocess_alter() is passed an $options array, which contains the endpoint resource and method. I need access to this information in the postprocess hook mentioned above, but don’t see any clean, Drupal-way to do that. this is what I am looking for.
The array looks as follows:
Array( [version] => , [resource] => node, [method] => 1.json );
Sponsored by SupremePR