diff --git a/core/includes/common.inc b/core/includes/common.inc index 93d52fa..175267f 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -148,62 +148,6 @@ const LOCALE_PLURAL_DELIMITER = "\03"; /** - * Adds output to the HEAD tag of the HTML page. - * - * This function can be called as long as the headers aren't sent. Pass no - * arguments (or NULL for both) to retrieve the currently stored elements. - * - * @param $data - * A renderable array. If the '#type' key is not set then 'html_tag' will be - * added as the default '#type'. - * @param $key - * A unique string key to allow implementations of hook_html_head_alter() to - * identify the element in $data. Required if $data is not NULL. - * - * @return - * An array of all stored HEAD elements. - * - * @see \Drupal\Core\Render\Element\HtmlTag::preRenderHtmlTag() - * - * @deprecated in Drupal 8.0.x, will be removed before Drupal 8.0.0 - * Use #attached on render arrays. - */ -function _drupal_add_html_head($data = NULL, $key = NULL) { - $stored_head = &drupal_static(__FUNCTION__, array()); - - if (isset($data) && isset($key)) { - if (!isset($data['#type'])) { - $data['#type'] = 'html_tag'; - } - $stored_head[$key] = $data; - } - return $stored_head; -} - -/** - * Retrieves output to be displayed in the HEAD tag of the HTML page. - * - * @param bool $render - * If TRUE render the HEAD elements, otherwise return just the elements. - * - * @return string|array - * Return the rendered HTML head or the elements itself. - * - * @deprecated in Drupal 8.0.x, will be removed before Drupal 8.0.0 - * Use #attached on render arrays. - */ -function drupal_get_html_head($render = TRUE) { - $elements = _drupal_add_html_head(); - \Drupal::moduleHandler()->alter('html_head', $elements); - if ($render) { - return \Drupal::service('renderer')->renderPlain($elements); - } - else { - return $elements; - } -} - -/** * Prepares a 'destination' URL query parameter for use with url(). * * Used to direct the user back to the referring page after completing a form. @@ -464,39 +408,6 @@ function base_path() { } /** - * Adds a LINK tag with a distinct 'rel' attribute to the page's HEAD. - * - * This function can be called as long the HTML header hasn't been sent, which - * on normal pages is up through the preprocess step of _theme('html'). Adding - * a link will overwrite a prior link with the exact same 'rel' and 'href' - * attributes. - * - * @param $attributes - * Associative array of element attributes including 'href' and 'rel'. - * @param $header - * Optional flag to determine if a HTTP 'Link:' header should be sent. - * - * @deprecated in Drupal 8.0.x, will be removed before Drupal 8.0.0 - * Use #attached on render arrays. - */ -function _drupal_add_html_head_link($attributes, $header = FALSE) { - $element = array( - '#tag' => 'link', - '#attributes' => $attributes, - ); - $href = $attributes['href']; - - if ($header) { - // Also add a HTTP header "Link:". - $href = '<' . SafeMarkup::checkPlain($attributes['href']) . '>;'; - unset($attributes['href']); - $element['#attached']['http_header'][] = array('Link', $href . drupal_http_header_attributes($attributes), TRUE); - } - - _drupal_add_html_head($element, 'html_head_link:' . $attributes['rel'] . ':' . $href); -} - -/** * Deletes old cached CSS files. * * @deprecated in Drupal 8.x, will be removed before Drupal 9.0. @@ -615,6 +526,9 @@ function drupal_merge_attached(array $a, array $b) { * * @throws LogicException * When attaching something of a non-existing attachment type. + * + * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0. Specify + * attached resources and directives in the render array. */ function drupal_process_attached(array $elements) { // Asset attachments are handled by \Drupal\Core\Asset\AssetResolver. @@ -628,16 +542,16 @@ function drupal_process_attached(array $elements) { // Limit the amount allowed entries. switch ($callback) { case 'html_head': - // @todo Remove validation in https://www.drupal.org/node/2477223 + // @todo Removed in https://www.drupal.org/node/2477223 break; case 'feed': - // @todo Remove validation in https://www.drupal.org/node/2477223 + // @todo Removed in https://www.drupal.org/node/2477223 break; case 'html_head_link': - // @todo Remove validation in https://www.drupal.org/node/2477223 + // @todo Removed in https://www.drupal.org/node/2477223 break; case 'http_header': - // @todo Remove validation in https://www.drupal.org/node/2477223 + // @todo Removed in https://www.drupal.org/node/2467759 break; default: throw new \LogicException(sprintf('You are not allowed to use %s in #attached', $callback)); diff --git a/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php b/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php index 5841ea4..b5b3c27 100644 --- a/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php +++ b/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php @@ -124,16 +124,33 @@ public function processAttachments(AttachmentsInterface $response) { // it's not present. if (!empty($placeholders['head'])) { - // feed is a special casse of html_head_link. + // feed is a special casse of html_head_link. We create an html_head_link + // for the RSS feed. if (!empty($attached['feed'])) { + // @todo: Determine if feed is supposed to be a single structure or an + // array of structures. $feed = $attached['feed']; - $feed_link = [ - 'href' => $feed[0], - 'rel' => 'alternate', - 'title' => $feed[1], - 'type' => 'application/rss+xml', - ]; - $attached['html_head_link'][] = $feed_link; + + if (is_array($feed[0])) { + foreach ($feed as $item) { + $feed_link = [ + 'href' => $item[0], + 'rel' => 'alternate', + 'title' => empty($feed[1]) ? '' : $item[1], + 'type' => 'application/rss+xml', + ]; + $attached['html_head_link'][] = [$feed_link]; + } + } + else { + $feed_link = [ + 'href' => $feed[0], + 'rel' => 'alternate', + 'title' => empty($feed[1]) ? '' : $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 @@ -142,9 +159,15 @@ public function processAttachments(AttachmentsInterface $response) { // 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); + // Merge $link_attached into $attached so that its html_head and + // http_header values are present for further processing. The merge + // requires a full render array, so we have to add #attached keys. + $attached = $this->renderer->mergeBubbleableMetadata( + ['#attached' => $attached], + ['#attached' => $link_attached] + ); + // Unwrap the #attached key. + $attached = $attached['#attached']; } // Now we can process html_head. @@ -156,7 +179,7 @@ public function processAttachments(AttachmentsInterface $response) { } } - // Now replace the placeholders in the response content with the real data. + // Replace the placeholders in the response content with the real data. $this->renderPlaceholders($response, $placeholders, $variables); // Set the HTTP headers on the response if any bubbled.