From b60ba446b23175b9f94f19859e5a19639ebabb5e Mon Sep 17 00:00:00 2001 From: David Coote Date: Mon, 23 Sep 2019 16:18:40 +0100 Subject: [PATCH 1/2] DD-1513 remove front page links the same way we do taxonomy terms page links --- src/Dennis/Link/Checker/Config.php | 18 ++++++++++++++++++ src/Dennis/Link/Checker/Link.php | 19 +++++++++++++++++++ src/Dennis/Link/Checker/LinkInterface.php | 7 +++++++ src/Dennis/Link/Checker/Processor.php | 4 +++- 4 files changed, 47 insertions(+), 1 deletion(-) 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..98087bd 100644 --- a/src/Dennis/Link/Checker/Link.php +++ b/src/Dennis/Link/Checker/Link.php @@ -258,6 +258,25 @@ public function redirectsToTerm() { return $this->data['redirects_to_term']; } + /** + * Check of the href redirects to a . + * + * @return bool + */ + public function redirectsToFront() { + if ($this->data['redirects_to_home']) { + return $this->data['redirects_to_home']; + } + + $this->data['redirects_to_home'] = FALSE; + if ($this->correctedHref() != $this->originalHref()) { + if($this->correctedHref() == '/') { + $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 | ' From 4766956835e94df178e61db15ea239d440a7bb5a Mon Sep 17 00:00:00 2001 From: Sergio Date: Wed, 25 Sep 2019 11:22:30 +0100 Subject: [PATCH 2/2] DD-1513 : compare as well with base url --- src/Dennis/Link/Checker/Link.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Dennis/Link/Checker/Link.php b/src/Dennis/Link/Checker/Link.php index 98087bd..6a1e650 100644 --- a/src/Dennis/Link/Checker/Link.php +++ b/src/Dennis/Link/Checker/Link.php @@ -264,13 +264,17 @@ public function redirectsToTerm() { * @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($this->correctedHref() == '/') { + if (in_array($this->correctedHref(), array('/', $baseurl))) { $this->data['redirects_to_home'] = TRUE; } }