diff --git a/src/Dennis/Link/Checker/Config.php b/src/Dennis/Link/Checker/Config.php index 1bf8dcd..4a5d517 100644 --- a/src/Dennis/Link/Checker/Config.php +++ b/src/Dennis/Link/Checker/Config.php @@ -23,6 +23,8 @@ class Config implements ConfigInterface { protected $removeTermLinks = TRUE; + protected $removeFrontLinks = TRUE; + protected $nids = FALSE; protected $fieldNames = []; @@ -124,6 +126,22 @@ public function removeTermLinks() { return $this->removeTermLinks; } + /** + * @inheritDoc + */ + public function setRemoveFrontLinks($remove) { + $this->removeFrontLinks = $remove; + + return $this; + } + + /** + * @inheritDoc + */ + public function removeFrontLinks() { + return $this->removeFrontLinks; + } + /** * @inheritDoc */ diff --git a/src/Dennis/Link/Checker/Link.php b/src/Dennis/Link/Checker/Link.php index 04bdbe5..6a1e650 100644 --- a/src/Dennis/Link/Checker/Link.php +++ b/src/Dennis/Link/Checker/Link.php @@ -258,6 +258,29 @@ public function redirectsToTerm() { return $this->data['redirects_to_term']; } + /** + * Check of the href redirects to a . + * + * @return bool + */ + public function redirectsToFront() { + $parsed_url = parse_url($this->originalHref()); + $baseurl = $parsed_url['scheme'] . '://' . $parsed_url['host'] . '/'; + + if ($this->data['redirects_to_home']) { + return $this->data['redirects_to_home']; + } + + $this->data['redirects_to_home'] = FALSE; + + if ($this->correctedHref() != $this->originalHref()) { + if (in_array($this->correctedHref(), array('/', $baseurl))) { + $this->data['redirects_to_home'] = TRUE; + } + } + return $this->data['redirects_to_home']; + } + /** * Helper function to try find a record for a given path. * diff --git a/src/Dennis/Link/Checker/LinkInterface.php b/src/Dennis/Link/Checker/LinkInterface.php index b889931..84dad8c 100644 --- a/src/Dennis/Link/Checker/LinkInterface.php +++ b/src/Dennis/Link/Checker/LinkInterface.php @@ -101,6 +101,13 @@ public function getError(); */ public function redirectsToTerm(); + /** + * Check if the href redirects to a taxonomy term. + * + * @return bool + */ + public function redirectsToFront(); + /** * Strip link. * diff --git a/src/Dennis/Link/Checker/Processor.php b/src/Dennis/Link/Checker/Processor.php index d8eb564..fd0c144 100644 --- a/src/Dennis/Link/Checker/Processor.php +++ b/src/Dennis/Link/Checker/Processor.php @@ -373,7 +373,9 @@ public function correctLinks(ItemInterface $item, FieldInterface $field) { public function updateLink(EntityInterface $entity, LinkInterface $link) { // Before doing the replacement, check if the link originally pointed to a node, and // now points to a term, and if so then remove the link altogether. See case 27710. - if ($this->config->removeTermLinks() && $link->redirectsToTerm()) { + if (($this->config->removeTermLinks() && $link->redirectsToTerm()) + || ($this->config->removeFrontLinks() && $link->redirectsToFront() + )) { // Strip link and keep the text part $link->strip(); $this->config->getLogger()->warning('LINK REMOVED | '