protected function AmpHtmlResponseAttachmentsProcessor::processHtmlHeadLink in Accelerated Mobile Pages (AMP) 8.3
Same name and namespace in other branches
- 8 src/Render/AmpHtmlResponseAttachmentsProcessor.php \Drupal\amp\Render\AmpHtmlResponseAttachmentsProcessor::processHtmlHeadLink()
- 8.2 src/Render/AmpHtmlResponseAttachmentsProcessor.php \Drupal\amp\Render\AmpHtmlResponseAttachmentsProcessor::processHtmlHeadLink()
Transform a html_head_link array into html_head and http_header arrays.
Variable html_head_link is a special case of html_head which can be present as a link item in the HTML head section, and also as a Link: HTTP header, depending on options in the render array. Processing it can add to both the html_head and http_header sections.
Parameters
array $html_head_link: The 'html_head_link' value of a render array. Each head link is specified by a two-element array:
- An array specifying the attributes of the link.
- A boolean specifying whether the link should also be a Link: HTTP header.
Return value
array An ['#attached'] section of a render array. This allows us to easily merge the results with other render arrays. The array could contain the following keys:
- http_header
- html_head
Overrides HtmlResponseAttachmentsProcessor::processHtmlHeadLink
File
- src/
Render/ AmpHtmlResponseAttachmentsProcessor.php, line 128
Class
- AmpHtmlResponseAttachmentsProcessor
- Processes attachments of AMP HTML responses.
Namespace
Drupal\amp\RenderCode
protected function processHtmlHeadLink(array $html_head_link) {
$attached = parent::processHtmlHeadLink($html_head_link);
if (array_key_exists('http_header', $attached)) {
// Find the amphtml link and flag it to be displayed as a HTTP header.
foreach ($attached['http_header'] as $key => $value) {
if (strpos($value[1], 'rel="amphtml"') !== FALSE) {
$new_value = str_replace(';', '', $value[1]);
$attached['http_header'][$key] = [
'Link',
$new_value,
TRUE,
];
}
}
}
return $attached;
}