Last active
March 14, 2024 08:32
-
-
Save matej21/a8dc7437852610c9e854 to your computer and use it in GitHub Desktop.
Backlink
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** @var string @persistent */ | |
public $_backlink; | |
public function link($destination, $args = []) | |
{ | |
$modifiers = []; | |
if (($pos = strrpos($destination, ')')) !== FALSE) { | |
$modifiers = array_fill_keys(explode(')(', substr($destination, 1, $pos - 1)), TRUE); | |
$destination = substr($destination, $pos + 1); | |
} | |
if (isset($modifiers['backlink'])) { | |
$url = $this->getHttpRequest()->getUrl(); | |
$args['_backlink'] = substr($url->getAbsoluteUrl(), strlen($url->getHostUrl())); | |
} elseif ($destination !== 'this') { | |
$args['_backlink'] = NULL; | |
} | |
return parent::link($destination, $args); | |
} | |
public function redirectToBacklink() | |
{ | |
if ($this->_backlink) { | |
$this->redirectUrl($this->_backlink); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment