Commit f577bdcb authored by catch's avatar catch

Issue #2566619 by claudiu.cristea, marvin_B8, andypost, alvar0hurtad0, Mile23,...

Issue #2566619 by claudiu.cristea, marvin_B8, andypost, alvar0hurtad0, Mile23, joshi.rohit100, dawehner, joelpittet: Deprecate drupal_http_header_attributes()
parent d8a6a68b
......@@ -14,6 +14,7 @@
use Drupal\Component\Utility\SortArray;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Render\HtmlResponseAttachmentsProcessor;
use Drupal\Core\Render\Element\Link;
use Drupal\Core\Render\Markup;
use Drupal\Core\StringTranslation\TranslatableMarkup;
......@@ -350,21 +351,22 @@ function date_iso8601($date) {
/**
* Formats an attribute string for an HTTP header.
*
* @param $attributes
* @param array $attributes
* An associative array of attributes such as 'rel'.
*
* @return
* @return string
* A ; separated string ready for insertion in a HTTP header. No escaping is
* performed for HTML entities, so this string is not safe to be printed.
*
* @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use
* \Drupal\Core\Render\HtmlResponseAttachmentsProcessor::formatHttpHeaderAttributes()
* instead.
*
* @see https://www.drupal.org/node/3000051
*/
function drupal_http_header_attributes(array $attributes = []) {
foreach ($attributes as $attribute => &$data) {
if (is_array($data)) {
$data = implode(' ', $data);
}
$data = $attribute . '="' . $data . '"';
}
return $attributes ? ' ' . implode('; ', $attributes) : '';
@trigger_error("drupal_http_header_attributes() is deprecated nn Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Render\HtmlResponseAttachmentsProcessor::formatHttpHeaderAttributes() instead. See https://www.drupal.org/node/3000051", E_USER_DEPRECATED);
return HtmlResponseAttachmentsProcessor::formatHttpHeaderAttributes($attributes);
}
/**
......
......@@ -218,6 +218,30 @@ public function processAttachments(AttachmentsInterface $response) {
return $response;
}
/**
* Formats an attribute string for an HTTP header.
*
* @param array $attributes
* An associative array of attributes such as 'rel'.
*
* @return string
* A ; separated string ready for insertion in a HTTP header. No escaping is
* performed for HTML entities, so this string is not safe to be printed.
*
* @internal
*
* @see https://www.drupal.org/node/3000051
*/
public static function formatHttpHeaderAttributes(array $attributes = []) {
foreach ($attributes as $attribute => &$data) {
if (is_array($data)) {
$data = implode(' ', $data);
}
$data = $attribute . '="' . $data . '"';
}
return $attributes ? ' ' . implode('; ', $attributes) : '';
}
/**
* Renders placeholders (#attached['placeholders']).
*
......@@ -421,7 +445,7 @@ protected function processHtmlHeadLink(array $html_head_link) {
// Also add a HTTP header "Link:".
$href = '<' . Html::escape($attributes['href']) . '>';
unset($attributes['href']);
if ($param = drupal_http_header_attributes($attributes)) {
if ($param = static::formatHttpHeaderAttributes($attributes)) {
$href .= ';' . $param;
}
......
<?php
namespace Drupal\KernelTests\Core\Render;
use Drupal\Core\Render\HtmlResponseAttachmentsProcessor;
use Drupal\KernelTests\KernelTestBase;
/**
* Deprecation tests cases for the render layer.
*
* @group legacy
*/
class RendererLegacyTest extends KernelTestBase {
/**
* Tests deprecation of the drupal_http_header_attributes() function.
*
* @dataProvider providerAttributes
*
* @expectedDeprecation drupal_http_header_attributes() is deprecated nn Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Render\HtmlResponseAttachmentsProcessor::formatHttpHeaderAttributes() instead. See https://www.drupal.org/node/3000051
*/
public function testHeaderAttributes($expected, $attributes) {
$this->assertSame($expected, drupal_http_header_attributes($attributes));
$this->assertSame($expected, HtmlResponseAttachmentsProcessor::formatHttpHeaderAttributes($attributes));
}
/**
* Provides a list of attributes to test.
*/
public function providerAttributes() {
return [
[' foo=""', ['foo' => '']],
[' foo=""', ['foo' => []]],
[' foo="bar"', ['foo' => 'bar']],
[' foo="bar"', ['foo' => ['bar']]],
[' foo="bar baz"', ['foo' => ['bar', 'baz']]],
];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment