You are here

protected function HtmlResponseAttachmentsProcessor::processHtmlHeadLink in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php \Drupal\Core\Render\HtmlResponseAttachmentsProcessor::processHtmlHeadLink()

Transform a html_head_link array into html_head and http_header arrays.

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
1 call to HtmlResponseAttachmentsProcessor::processHtmlHeadLink()
HtmlResponseAttachmentsProcessor::processAttachments in core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php
Processes the attachments of a response that has attachments.

File

core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php, line 410
Contains \Drupal\Core\Render\HtmlResponseAttachmentsProcessor.

Class

HtmlResponseAttachmentsProcessor
Processes attachments of HTML responses.

Namespace

Drupal\Core\Render

Code

protected function processHtmlHeadLink(array $html_head_link) {
  $attached = [];
  foreach ($html_head_link as $item) {
    $attributes = $item[0];
    $should_add_header = isset($item[1]) ? $item[1] : FALSE;
    $element = array(
      '#tag' => 'link',
      '#attributes' => $attributes,
    );
    $href = $attributes['href'];
    $attached['html_head'][] = [
      $element,
      'html_head_link:' . $attributes['rel'] . ':' . $href,
    ];
    if ($should_add_header) {

      // Also add a HTTP header "Link:".
      $href = '<' . Html::escape($attributes['href'] . '>');
      unset($attributes['href']);
      $attached['http_header'][] = [
        'Link',
        $href . drupal_http_header_attributes($attributes),
        TRUE,
      ];
    }
  }
  return $attached;
}