public function TestController::format in Drupal 10
Same name and namespace in other branches
- 8 core/modules/system/tests/modules/conneg_test/src/Controller/TestController.php \Drupal\conneg_test\Controller\TestController::format()
- 9 core/modules/system/tests/modules/conneg_test/src/Controller/TestController.php \Drupal\conneg_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'
- conneg_test.routing.yml in core/
modules/ system/ tests/ modules/ conneg_test/ conneg_test.routing.yml - core/modules/system/tests/modules/conneg_test/conneg_test.routing.yml
File
- core/
modules/ system/ tests/ modules/ conneg_test/ src/ Controller/ TestController.php, line 43
Class
- TestController
- Test controller for content negotiation tests.
Namespace
Drupal\conneg_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());
}
}