Commit 65eedec5 authored by Sabina Halkic's avatar Sabina Halkic Committed by Damien McKenna
Browse files

Issue #3241256 by ndf, sabina.h, idebr, DamienMcKenna: Remove redundant HTTP...

Issue #3241256 by ndf, sabina.h, idebr, DamienMcKenna: Remove redundant HTTP headers for canonical and short_link tags.
parent 6193da84
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -12,6 +12,8 @@ Metatag 8.x-1.x-dev, 2022-xx-xx
#3261505 by DamienMcKenna, Eugene Bocharov, Sergiu Stici: In php 8.1 the explode
  function throws a notice when default value is null.
#3265679 by DamienMcKenna: Additional coding standards bugs.
#3241256 by ndf, sabina.h, idebr, DamienMcKenna: Remove redundant HTTP headers
  for canonical and short_link tags.


Metatag 8.x-1.19, 2022-01-06
+0 −27
Original line number Diff line number Diff line
@@ -144,7 +144,6 @@ function metatag_page_attachments(array &$attachments) {
      $attachments['#attached']['html_head'] = [];
    }

    $head_links = [];
    foreach ($metatag_attachments['#attached']['html_head'] as $item) {
      // Do not attach a title meta tag as this unnecessarily duplicates the
      // title tag.
@@ -154,32 +153,6 @@ function metatag_page_attachments(array &$attachments) {
      }

      $attachments['#attached']['html_head'][] = $item;

      // Also add a HTTP header "Link:" for canonical URLs and shortlinks.
      // See HtmlResponseAttachmentsProcessor::processHtmlHeadLink() for the
      // implementation of the functionality in core.
      if (isset($item[0]['#attributes']['href'])) {
        if (in_array($item[1], ['canonical_url', 'shortlink'])) {
          $attributes = $item[0]['#attributes'];

          $href = '<' . Html::escape($attributes['href']) . '>';
          unset($attributes['href']);
          $param = HtmlResponseAttachmentsProcessor::formatHttpHeaderAttributes($attributes);
          if (!empty($param)) {
            $href .= ';' . $param;
          }
          $head_links[] = $href;
        }
      }
    }

    // If any HTTP Header items were found, add them too.
    if (!empty($head_links)) {
      $attachments['#attached']['http_header'][] = [
        'Link',
        implode(', ', $head_links),
        FALSE,
      ];
    }
  }
}