Skip to content

Instantly share code, notes, and snippets.

@miznokruge
Forked from matej21/BasePresenter.php
Created April 27, 2018 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miznokruge/b22eac73ed82cef990ed1d8c6a20e4cb to your computer and use it in GitHub Desktop.
Save miznokruge/b22eac73ed82cef990ed1d8c6a20e4cb to your computer and use it in GitHub Desktop.
Backlink
<?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