protected function PageProcessor::processTagA in Mini site 8
Process <a> tag.
Parameters
\DOMNode $item: Document node object to process.
1 call to PageProcessor::processTagA()
- PageProcessor::process in src/
PageProcessor.php - Process document.
File
- src/
PageProcessor.php, line 113
Class
- PageProcessor
- Class PageProcessor.
Namespace
Drupal\minisiteCode
protected function processTagA(\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;
}
// If href is a relative path - skip processing as it is not possible to
// "guess" the correct files in the tree (i.e., could be pointing to the
// file with the same name from another dir etc., which is even more
// confusing).
if (UrlValidator::urlIsRelative($url) && self::urlIsDocumentFile($url)) {
$url = self::urlExtractPath($url);
$url = UrlValidator::relativeToRoot($url, $this->urlBag
->getAssetDir() . '/' . $this->urlBag
->getRootDir());
$item
->setAttribute('href', $url);
return;
}
}