-
-
Save miznokruge/b22eac73ed82cef990ed1d8c6a20e4cb to your computer and use it in GitHub Desktop.
Backlink
This file contains 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