From 9e5c7a32e3d3c1726f5f7695f0ba829269735f88 Mon Sep 17 00:00:00 2001 From: vv221 Date: Tue, 28 Apr 2020 13:11:30 +0200 Subject: [PATCH] Add ability to identify a link to the current page A new MenuItem boolean property is available, $is_active: - its value is true if the link points to the current page - its value is false otherwise --- MenuItem.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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