function TestController::format
Same name in other branches
- 9 core/modules/system/tests/modules/conneg_test/src/Controller/TestController.php \Drupal\conneg_test\Controller\TestController::format()
- 8.9.x core/modules/system/tests/modules/conneg_test/src/Controller/TestController.php \Drupal\conneg_test\Controller\TestController::format()
- 11.x core/modules/system/tests/modules/content_negotiation_test/src/Controller/TestController.php \Drupal\content_negotiation_test\Controller\TestController::format()
Returns different responses depending on the request format.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The request
Return value
\Symfony\Component\HttpFoundation\Response The response.
1 string reference to 'TestController::format'
- content_negotiation_test.routing.yml in core/
modules/ system/ tests/ modules/ content_negotiation_test/ content_negotiation_test.routing.yml - core/modules/system/tests/modules/content_negotiation_test/content_negotiation_test.routing.yml
File
-
core/
modules/ system/ tests/ modules/ content_negotiation_test/ src/ Controller/ TestController.php, line 43
Class
- TestController
- Test controller for content negotiation tests.
Namespace
Drupal\content_negotiation_test\ControllerCode
public function format(Request $request) {
switch ($request->getRequestFormat()) {
case 'json':
return new JsonResponse([
'some' => 'data',
]);
case 'xml':
return new Response('<xml></xml>', Response::HTTP_OK, [
'Content-Type' => 'application/xml',
]);
default:
return new Response($request->getRequestFormat());
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.