Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
It would be nice to be able to have a user-defined fallback (i.e. variable_get/set). This was possible in 7.x-3.3 and earlier before the major architectural changes, but ServicesContentTypeNegotiator class is in charge of this now. In order to change this I would need to rewrite rest_server or hack services.
ServicesContentTypeNegotiator::getResponseFormatContentTypeNegotiations()
diff --git a/servers/rest_server/includes/ServicesContentTypeNegotiator.inc b/servers/rest_server/includes/ServicesContentTypeNegotiator.inc
index cc7ec27..4b2f1fb 100644
--- a/servers/rest_server/includes/ServicesContentTypeNegotiator.inc
+++ b/servers/rest_server/includes/ServicesContentTypeNegotiator.inc
@@ -84,7 +84,7 @@ class ServicesContentTypeNegotiator implements ServicesContentTypeNegotiatorInte
}
// Get the best matching format, default to json
- $response_format = 'json';
+ $response_format = variable_get('rest_server_default_response_format', 'json');
$http_accept = $context->getServerVariable('HTTP_ACCEPT');
if (!empty($http_accept)) {
$mime = $this->mimeParse();
I will post a patch shortly.
Comment | File | Size | Author |
---|---|---|---|
#1 | services-2072819-provide-default-response-format-1.patch | 1.15 KB | mradcliffe |
Comments
Comment #1
mradcliffeThis changes the default string to a variable_get and adds a hook_uninstall() implementation to rest_server to clean up.
Comment #2
marcingy CreditAttribution: marcingy commentedlooks good
Comment #3
ygerasimov CreditAttribution: ygerasimov commentedCommitted. Also added some documentation about introduced variable.