diff --git a/MenuItem.php b/MenuItem.php index cdf1fb1..3326c4e 100644 --- a/MenuItem.php +++ b/MenuItem.php @@ -5,6 +5,11 @@ namespace dokuwiki\plugin\childrenpages; use dokuwiki\Menu\Item\AbstractItem; class MenuItem extends AbstractItem { + /** + * @var bool $is_active True if it is a link to the current page + */ + public bool $is_active; + /** * Generate a menu item from a passed string * @@ -24,6 +29,7 @@ class MenuItem extends AbstractItem { $this->label = $label; parent::__construct(); $this->setTargetFromType($type, $strip_namespace); + $this->setIsActive(); } /** @@ -69,6 +75,16 @@ class MenuItem extends AbstractItem { $this->params = []; } + /** + * Set the active status of the link + */ + protected function setIsActive() : void { + global $INFO; + $current_page_id = $INFO['id']; + $target_page_id = $this->id; + $this->is_active = ( $target_page_id === $current_page_id ); + } + /** * Convenience method to get the attributes for constructing an element * Parent method is declared in dokuwiki\Menu\Item\AbstractItem