public function HtmlResponse::setContent in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Render/HtmlResponse.php \Drupal\Core\Render\HtmlResponse::setContent()
Sets the response content.
Valid types are strings, numbers, null, and objects that implement a __toString() method.
Parameters
mixed $content Content that can be cast to string:
Return value
Throws
\UnexpectedValueException
Overrides Response::setContent
File
- core/
lib/ Drupal/ Core/ Render/ HtmlResponse.php, line 35 - Contains \Drupal\Core\Render\HtmlResponse.
Class
- HtmlResponse
- A response that contains and can expose cacheability metadata and attachments.
Namespace
Drupal\Core\RenderCode
public function setContent($content) {
// A render array can automatically be converted to a string and set the
// necessary metadata.
if (is_array($content) && isset($content['#markup'])) {
$content += [
'#attached' => [
'html_response_attachment_placeholders' => [],
'placeholders' => [],
],
];
$this
->addCacheableDependency(CacheableMetadata::createFromRenderArray($content));
$this
->setAttachments($content['#attached']);
$content = $content['#markup'];
}
return parent::setContent($content);
}