id)->SKIPLINKS_ENABLE; } /** * Inserts container for skip links in page layout. */ public static function insertContainer() { if (!self::isEnabled()) { return; } PageLayout::addBodyElements('
'); } /** * Adds a link to the list of skip links. * * @param string $name the displayed name of the links * @param string $url the url of the links * @param integer $position the position of the link in the list */ public static function addLink(string $name, string $url, $position = null) { $position = (!$position || $position < 1) ? count(self::$links) + 100 : (int) $position; self::$links[$url] = [ 'name' => $name, 'url' => $url, 'position' => $position, ]; } /** * Adds a link to an anker on the same page to the list of skip links. * * @param string $name the displayed name of the links * @param string $id the id of the anker * @param integer $position the position of the link in the list */ public static function addIndex($name, $id, $position = null) { $url = '#' . $id; self::addLink($name, $url, $position); } /** * Returns the formatted list of skip links * * @return string the formatted list of skip links */ public static function getHTML() { if (!self::isEnabled() || count(self::$links) === 0) { return ''; } usort(self::$links, function ($a, $b) { return $a['position'] - $b['position']; }); $navigation = new Navigation(''); foreach (array_values(self::$links) as $index => $link) { $navigation->addSubNavigation( "/skiplinks/link-{$index}", new Navigation($link['name'], $link['url']) ); } return $GLOBALS['template_factory']->render('skiplinks', compact('navigation')); } }