comparison core/lib/Drupal/Core/Render/HtmlResponse.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\Core\Render;
4
5 use Drupal\Core\Cache\CacheableMetadata;
6 use Drupal\Core\Cache\CacheableResponseInterface;
7 use Drupal\Core\Cache\CacheableResponseTrait;
8 use Symfony\Component\HttpFoundation\Response;
9
10 /**
11 * A response that contains and can expose cacheability metadata and attachments.
12 *
13 * Supports Drupal's caching concepts: cache tags for invalidation and cache
14 * contexts for variations.
15 *
16 * Supports Drupal's idea of #attached metadata: libraries, settings, http_header and html_head.
17 *
18 * @see \Drupal\Core\Cache\CacheableResponse
19 * @see \Drupal\Core\Render\AttachmentsInterface
20 * @see \Drupal\Core\Render\AttachmentsTrait
21 */
22 class HtmlResponse extends Response implements CacheableResponseInterface, AttachmentsInterface {
23
24 use CacheableResponseTrait;
25 use AttachmentsTrait;
26
27 /**
28 * {@inheritdoc}
29 */
30 public function setContent($content) {
31 // A render array can automatically be converted to a string and set the
32 // necessary metadata.
33 if (is_array($content) && (isset($content['#markup']))) {
34 $content += [
35 '#attached' => [
36 'html_response_attachment_placeholders' => [],
37 'placeholders' => [],
38 ],
39 ];
40 $this->addCacheableDependency(CacheableMetadata::createFromRenderArray($content));
41 $this->setAttachments($content['#attached']);
42 $content = $content['#markup'];
43 }
44
45 return parent::setContent($content);
46 }
47
48 }