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:
parent
b2c7692a59
commit
c24b382c3b
1 changed files with 22 additions and 0 deletions
22
MenuItem.php
22
MenuItem.php
|
@ -68,4 +68,26 @@ class MenuItem extends AbstractItem {
|
||||||
$this->id = implode(':', array_merge($target_path, $page_path));
|
$this->id = implode(':', array_merge($target_path, $page_path));
|
||||||
$this->params = [];
|
$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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue