Skip to content

Commit

Permalink
Merge pull request #15 from dennisinteractive/DD-1513-remove-front-pa…
Browse files Browse the repository at this point in the history
…ge-links

DD-1513 remove front page links the same way we do taxonomy terms pag…
  • Loading branch information
audave authored Sep 30, 2019
2 parents 1718276 + 4766956 commit 7efdcb1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/Dennis/Link/Checker/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Config implements ConfigInterface {

protected $removeTermLinks = TRUE;

protected $removeFrontLinks = TRUE;

protected $nids = FALSE;

protected $fieldNames = [];
Expand Down Expand Up @@ -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
*/
Expand Down
23 changes: 23 additions & 0 deletions src/Dennis/Link/Checker/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,29 @@ public function redirectsToTerm() {
return $this->data['redirects_to_term'];
}

/**
* Check of the href redirects to a <front>.
*
* @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.
*
Expand Down
7 changes: 7 additions & 0 deletions src/Dennis/Link/Checker/LinkInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
4 changes: 3 additions & 1 deletion src/Dennis/Link/Checker/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 | '
Expand Down

0 comments on commit 7efdcb1

Please sign in to comment.