class HtmlResponse in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Render/HtmlResponse.php \Drupal\Core\Render\HtmlResponse
A response that contains and can expose cacheability metadata and attachments.
Supports Drupal's caching concepts: cache tags for invalidation and cache contexts for variations.
Supports Drupal's idea of #attached metadata: libraries, settings, http_header and html_head.
Hierarchy
- class \Drupal\Core\Render\HtmlResponse extends \Symfony\Component\HttpFoundation\Response implements CacheableResponseInterface, AttachmentsInterface uses CacheableResponseTrait, AttachmentsTrait
Expanded class hierarchy of HtmlResponse
See also
\Drupal\Core\Cache\CacheableResponse
\Drupal\Core\Render\AttachmentsInterface
\Drupal\Core\Render\AttachmentsTrait
12 files declare their use of HtmlResponse
- BigPipe.php in core/
modules/ big_pipe/ src/ Render/ BigPipe.php - BigPipeResponse.php in core/
modules/ big_pipe/ src/ Render/ BigPipeResponse.php - BigPipeResponseAttachmentsProcessor.php in core/
modules/ big_pipe/ src/ Render/ BigPipeResponseAttachmentsProcessor.php - BigPipeResponseAttachmentsProcessorTest.php in core/
modules/ big_pipe/ tests/ src/ Unit/ Render/ BigPipeResponseAttachmentsProcessorTest.php - BigPipeTestSubscriber.php in core/
modules/ big_pipe/ tests/ modules/ big_pipe_test/ src/ EventSubscriber/ BigPipeTestSubscriber.php
File
- core/
lib/ Drupal/ Core/ Render/ HtmlResponse.php, line 22
Namespace
Drupal\Core\RenderView source
class HtmlResponse extends Response implements CacheableResponseInterface, AttachmentsInterface {
use CacheableResponseTrait;
use AttachmentsTrait;
/**
* {@inheritdoc}
*/
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);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AttachmentsTrait:: |
protected | property | The attachments for this response. | |
AttachmentsTrait:: |
public | function | ||
AttachmentsTrait:: |
public | function | ||
AttachmentsTrait:: |
public | function | ||
CacheableResponseTrait:: |
protected | property | The cacheability metadata. | |
CacheableResponseTrait:: |
public | function | ||
CacheableResponseTrait:: |
public | function | ||
HtmlResponse:: |
public | function | Sets the response content. |