function AjaxRenderer::renderResponse
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Render/MainContent/AjaxRenderer.php \Drupal\Core\Render\MainContent\AjaxRenderer::renderResponse()
- 10 core/lib/Drupal/Core/Render/MainContent/AjaxRenderer.php \Drupal\Core\Render\MainContent\AjaxRenderer::renderResponse()
- 9 core/lib/Drupal/Core/Render/MainContent/AjaxRenderer.php \Drupal\Core\Render\MainContent\AjaxRenderer::renderResponse()
- 8.9.x core/lib/Drupal/Core/Render/MainContent/AjaxRenderer.php \Drupal\Core\Render\MainContent\AjaxRenderer::renderResponse()
File
-
core/
lib/ Drupal/ Core/ Render/ MainContent/ AjaxRenderer.php, line 48
Class
- AjaxRenderer
- Default main content renderer for Ajax requests.
Namespace
Drupal\Core\Render\MainContentCode
public function renderResponse(array $main_content, Request $request, RouteMatchInterface $route_match) {
$response = new AjaxResponse();
$html = $this->renderer
->renderRoot($main_content);
$response->setAttachments($main_content['#attached']);
// The selector for the insert command is NULL as the new content will
// replace the element making the Ajax call. The default 'replaceWith'
// behavior can be changed with #ajax['method'].
$response->addCommand(new InsertCommand(NULL, $html));
$status_messages = [
'#type' => 'status_messages',
];
$output = $this->renderer
->renderRoot($status_messages);
if (!empty($output)) {
$response->addCommand(new PrependCommand(NULL, $output));
}
return $response;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.