/** * Replace a "[sitetree_link id=n]" shortcode with a link to the page with the corresponding ID. * * @param array $arguments * @param string $content * @param TextParser $parser * @return string */ public static 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'])) && !($page = Versioned::get_latest_version('SiteTree', $arguments['id'])) && !($page = DataObject::get_one('ErrorPage', '"ErrorPage"."ErrorCode" = \'404\''))) { 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; } }