Allow identification of links to non-existing pages

An extra class is added to generated links:
- "wikilink1" for links to existing pages
- "wikilink2" for links to new pages
This commit is contained in:
vv221 2020-04-28 12:52:46 +02:00
parent b2c7692a59
commit c24b382c3b

View file

@ -68,4 +68,26 @@ class MenuItem extends AbstractItem {
$this->id = implode(':', array_merge($target_path, $page_path));
$this->params = [];
}
/**
* Convenience method to get the attributes for constructing an <a> element
* Parent method is declared in dokuwiki\Menu\Item\AbstractItem
*
* @param string|false $classprefix create a class from type with this prefix, false for no class
*
* @return array
*/
public function getLinkAttributes($classprefix = 'menuitem ') : array {
$attributes = parent::getLinkAttributes($classprefix);
// Get already set classes, defaulting to an empty string
$classes = ( isset($attributes['class']) ) ?
$attributes['class'] : '';
// Add an extra class, based on the existence of the target page
$extra_class = ( page_exists($this->id) ) ?
'wikilink1' : 'wikilink2';
$classes = trim("$classes $extra_class");
// Return the full attributes list, including the updated classes list
$attributes['class'] = $classes;
return $attributes;
}
}