diff --git a/core/includes/common.inc b/core/includes/common.inc index 5fd753d..93d52fa 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -631,13 +631,7 @@ function drupal_process_attached(array $elements) { // @todo Remove validation in https://www.drupal.org/node/2477223 break; case 'feed': - $args = [[ - 'href' => $args[0], - 'rel' => 'alternate', - 'title' => $args[1], - 'type' => 'application/rss+xml', - ]]; - call_user_func_array('_drupal_add_html_head_link', $args); + // @todo Remove validation in https://www.drupal.org/node/2477223 break; case 'html_head_link': // @todo Remove validation in https://www.drupal.org/node/2477223 diff --git a/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php b/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php index 2c57845..5841ea4 100644 --- a/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php +++ b/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php @@ -11,6 +11,7 @@ use Drupal\Core\Asset\AttachedAssets; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Component\Utility\SafeMarkup; use Symfony\Component\HttpFoundation\RequestStack; /** @@ -118,21 +119,36 @@ public function processAttachments(AttachmentsInterface $response) { $variables = $this->processAssetLibraries($attached, $placeholders); - // If there is a 'head' placeholder, then we can process html_head and - // html_head_link. - if (isset($placeholders['head'])) { + // Since we can only replace content in the HTML head section if there's a + // placeholder for it, we can safely avoid processing the render array if + // it's not present. + if (!empty($placeholders['head'])) { + + // feed is a special casse of html_head_link. + if (!empty($attached['feed'])) { + $feed = $attached['feed']; + $feed_link = [ + 'href' => $feed[0], + 'rel' => 'alternate', + 'title' => $feed[1], + 'type' => 'application/rss+xml', + ]; + $attached['html_head_link'][] = $feed_link; + } + // html_head_link is a special case of html_head which can be present as // a head element, but also as a Link: http header depending on settings // in the render array. Processing it can add to both the html_head and - // http_header sections, so we must address it first. - if (isset($attached['html_head_link'])) { + // http_header keys of #attached, so we must address it first. + if (!empty($attached['html_head_link'])) { $link_attached = $this->processHtmlHeadLink($attached['html_head_link']); // Merge $link_attached so that its html_head and http_header // sections are present for further processing. $attached = array_merge($attached, $link_attached); } + // Now we can process html_head. - if (isset($attached['html_head'])) { + if (!empty($attached['html_head'])) { $head = $this->processHtmlHead($attached['html_head']); // Invoke hook_html_head_alter(). $this->moduleHandler->alter('html_head', $head); @@ -140,19 +156,10 @@ public function processAttachments(AttachmentsInterface $response) { } } - // Some elements are still handled by drupal_process_attached(). - $all_attached = ['#attached' => $attached]; - drupal_process_attached($all_attached); - // We have to get these elements back from the legacy system using - // drupal_get_html_head(). - if (isset($placeholders['head'])) { - $variables['head'] = array_merge($variables['head'], drupal_get_html_head(FALSE)); - } - // Now replace the placeholders in the response content with the real data. $this->renderPlaceholders($response, $placeholders, $variables); - // Finally set the headers on the response if any bubbled. + // Set the HTTP headers on the response if any bubbled. if (!empty($attached['http_header'])) { $this->setHeaders($response, $attached['http_header']); } @@ -278,12 +285,12 @@ protected function processHtmlHead(array $html_head) { * 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 head element, but also as a Link: http header depending on settings - * in the render array. Processing it can add to both the html_head and - * http_header sections. + * 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. * * @param array $html_head_link - * The 'html_head_link' section of a render array. + * The 'html_head_link' value of a render array. * * @return array * An ['#attached'] section of a render array. This allows us to easily @@ -298,6 +305,7 @@ protected function processHtmlHeadLink(array $html_head_link) { foreach ($html_head_link as $item) { $attributes = $item[0]; $should_add_header = isset($item[1]) ? $item[1] : FALSE; + $element = array( '#tag' => 'link', '#attributes' => $attributes, @@ -311,9 +319,8 @@ protected function processHtmlHeadLink(array $html_head_link) { unset($attributes['href']); $attached['http_header'][] = ['Link', $href . drupal_http_header_attributes($attributes), TRUE]; } - - return $attached; } + return $attached; } }