Created
May 16, 2014 00:25
-
-
Save anonymous/96cfcbae0364411ea806 to your computer and use it in GitHub Desktop.
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
static public function link_shortcode_handler($arguments, $content = null, $parser = null) { | |
if (!isset($arguments['id']) || !is_numeric($arguments['id'])) | |
return; | |
if ( | |
!($page = DataObject::get_by_id('SiteTree', $arguments['id'])) // Get the current page by ID. | |
&& !($page = Versioned::get_latest_version('SiteTree', $arguments['id'])) // Attempt link to old version. | |
&& !($page = DataObject::get_one('ErrorPage', '"ErrorPage"."ErrorCode" = \'404\'')) // Link to 404 page. | |
) { | |
return; // There were no suitable matches at all. | |
} | |
$link = Convert::raw2att($page->Link()); | |
if ($content) { | |
return sprintf('<a href="%s">%s</a>', $link, $parser->parse($content)); | |
} else { | |
return $link; | |
} | |
} | |
/* _config.php */ | |
ShortcodeParser::get('default')->register('sitetree_link', array('Block_HTMLArea', 'link_shortcode_handler')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment