You are here

protected function PageProcessor::processTagLink in Mini site 8

Process <link> tag.

Parameters

\DOMNode $item: Document node object to process.

1 call to PageProcessor::processTagLink()
PageProcessor::process in src/PageProcessor.php
Process document.

File

src/PageProcessor.php, line 157

Class

PageProcessor
Class PageProcessor.

Namespace

Drupal\minisite

Code

protected function processTagLink(\DOMNode $item) {
  $url = $item
    ->getAttribute('href');
  if (!$url) {
    return;
  }

  // Skip absolute URLs, because we cannot guarantee the correctness of any
  // replacements.
  if (UrlValidator::urlIsExternal($url)) {
    return;
  }

  // If href points to a root of the file structure - we are most likely in
  // the document linking to the root of the archive, so we have to replace
  // it with a relative path to the root (based on the current document
  // depth).
  // Note, that this is a case when we are "fixing" links that should not be
  // linking to root, so this is still a "best effort" approach.
  if (UrlValidator::urlIsRoot($url)) {
    $item
      ->setAttribute('href', UrlValidator::rootToRelative($url, $this->urlBag
      ->getRootDir(), $this->urlBag
      ->getParentAlias()));
    return;
  }
  $url = self::urlExtractPath($url);
  $url = UrlValidator::relativeToRoot($url, $this->urlBag
    ->getAssetDir() . '/' . $this->urlBag
    ->getRootDir());
  $item
    ->setAttribute('href', $url);
}