You are here

function hook_rest_server_response_formatters_alter in Services 6.3

Same name and namespace in other branches
  1. 7.3 docs/services.alter.api.php \hook_rest_server_response_formatters_alter()
  2. 7.3 servers/rest_server/rest_server.api.php \hook_rest_server_response_formatters_alter()

Triggered when the REST server request a list of supported response formats.

Parameters

array $formatters: An associative array of formatter info arrays keyed by type extension. The formatter info specifies an array of 'mime types' that corresponds to the output format; a 'view' class that is a subclass of RESTServerView; and 'view arguments' that should be passed to the view when it is created; a 'model' can also be specified which the controller then must declare support for to be able to serve data in that format.

Return value

void

1 function implements hook_rest_server_response_formatters_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

xcal_format_rest_server_response_formatters_alter in servers/rest_server/formats/xcal_format.module
1 invocation of hook_rest_server_response_formatters_alter()
rest_server_response_formatters in servers/rest_server/rest_server.module
Builds a list of response formatters that are available to the RESTServer.

File

servers/rest_server/rest_server.api.php, line 37
Hooks provided by Services for the definition of servers.

Code

function hook_rest_server_response_formatters_alter(&$formatters) {

  /*
   * Sample modifications of the formatters array. Both yaml and
   * rss are formats that already are supported, so the changes are
   * nonsensical but illustrates the proper use of this hook.
   */

  // Add a Yaml response format conditionally.
  if (_rest_server_get_spyc_location() !== false) {
    $formatters['yaml'] = array(
      'mime types' => array(
        'text/plain',
        'application/x-yaml',
        'text/yaml',
      ),
      'view' => 'RESTServerViewBuiltIn',
      'view arguments' => array(
        'format' => 'yaml',
      ),
    );
  }

  // Add a Rss response format.
  $formatters['rss'] = array(
    'model' => 'ResourceFeedModel',
    'mime types' => array(
      'text/xml',
    ),
    'view' => 'RssFormatView',
  );

  // Remove the jsonp response format.
  unset($formatters['jsonp']);
}