Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. HtmlResponse.php

function HtmlResponse::setContent

Sets the response content.

Parameters

mixed $content: Content that can be cast to string, or a render array.

Return value

$this

Overrides Response::setContent

1 call to HtmlResponse::setContent()
HtmlResponse::__construct in core/lib/Drupal/Core/Render/HtmlResponse.php
Constructs a HtmlResponse object.

File

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

Class

HtmlResponse
Response that contains and can expose cacheability metadata and attachments.

Namespace

Drupal\Core\Render

Code

public function setContent($content) : static {
    // 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);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal