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