Drupal 7 Services — hook_services_request_postprocess_alter() does not identify the requested resource

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
This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Drupal 7 Services — hook_services_request_postprocess_alter() does not identify the requested resource

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.