W3cubDocs

/Drupal 8

public function HtmlResponse::setContent

public HtmlResponse::setContent($content)

Sets the response content.

Valid types are strings, numbers, null, and objects that implement a __toString() method.

Parameters

mixed $content Content that can be cast to string:

Return value

Response

Throws

\UnexpectedValueException

Overrides Response::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);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!HtmlResponse.php/function/HtmlResponse::setContent/8.1.x