diff --git a/core/lib/Drupal/Core/Render/HtmlResponse.php b/core/lib/Drupal/Core/Render/HtmlResponse.php index 21a21805fe9..75b8b29ae3a 100644 --- a/core/lib/Drupal/Core/Render/HtmlResponse.php +++ b/core/lib/Drupal/Core/Render/HtmlResponse.php @@ -24,7 +24,27 @@ class HtmlResponse extends Response implements CacheableResponseInterface, Attac use CacheableResponseTrait; use AttachmentsTrait; - public function __construct($content = '', int $status = 200, array $headers = []) { + public function __construct( + ?string $content = '', + int $status = 200, + array $headers = [] + ) { + parent::__construct($this->getMarkup($content), $status, $headers); + } + + /** + * {@inheritdoc} + */ + public function setContent($content) { + return parent::setContent($this->getMarkup($content)); + } + + /** + * @param mixed $content + * + * @return array[]|mixed|string + */ + protected function getMarkup($content = '') { // A render array can automatically be converted to a string and set the // necessary metadata. if (is_array($content) && (isset($content['#markup']))) { @@ -38,8 +58,7 @@ public function __construct($content = '', int $status = 200, array $headers = [ $this->setAttachments($content['#attached']); $content = $content['#markup']; } - - parent::__construct($content, $status, $headers); + return $content; } } diff --git a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php index c326859cf29..8a53ff01059 100644 --- a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php +++ b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php @@ -140,6 +140,7 @@ public static function getSkippedDeprecations() { // Deprecation introduced in Symfony 5 'Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Alias::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.', 'Since symfony/dependency-injection 5.1: The signature of method "Symfony\Component\DependencyInjection\Definition::setDeprecated()" requires 3 arguments: "string $package, string $version, string $message", not defining them is deprecated.', + 'Since symfony/http-foundation 5.1: Retrieving a non-string value from "Symfony\Component\HttpFoundation\InputBag::get()" is deprecated, and will throw a "Symfony\Component\HttpFoundation\Exception\BadRequestException" exception in Symfony 6.0, use "Symfony\Component\HttpFoundation\InputBag::all($key)" instead.' ]; // Deprecations introduced in Symfony 5