function HtmlResponse::setContent

Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/HtmlResponse.php \Drupal\Core\Render\HtmlResponse::setContent()
  2. 10 core/lib/Drupal/Core/Render/HtmlResponse.php \Drupal\Core\Render\HtmlResponse::setContent()
  3. 11.x core/lib/Drupal/Core/Render/HtmlResponse.php \Drupal\Core\Render\HtmlResponse::setContent()

File

core/lib/Drupal/Core/Render/HtmlResponse.php, line 30

Class

HtmlResponse
A response that contains and can expose cacheability metadata and attachments.

Namespace

Drupal\Core\Render

Code

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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.