diff --git a/MenuItem.php b/MenuItem.php index 87a9f56..cdf1fb1 100644 --- a/MenuItem.php +++ b/MenuItem.php @@ -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 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; + } }