From c19d9693e92c87def4ec159a77f64de0c1b3584f Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Thu, 6 Jul 2023 12:03:10 +0100 Subject: [PATCH] MDL-78656 output: display menu item titles in primary navigation. Since custom menu items were merged into the primary navigation/more menu as part of 56c34d71 and related work, the "title" attribute of each custom menu item was lost. --- lib/navigationlib.php | 17 +++++++++++++---- lib/templates/moremenu_children.mustache | 19 ++++++++++++++++--- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 11522aa9c9b..4dc220ffd1b 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -582,11 +582,20 @@ class navigation_node implements renderable { /** * Sets the title for this node and forces Moodle to utilise it. - * @param string $title + * + * Note that this method is named identically to the public "title" property of the class, which unfortunately confuses + * our Mustache renderer, because it will see the method and try and call it without any arguments (hence must be nullable) + * before trying to access the public property + * + * @param string|null $title + * @return string */ - public function title($title) { - $this->title = $title; - $this->forcetitle = true; + public function title(?string $title = null): string { + if ($title !== null) { + $this->title = $title; + $this->forcetitle = true; + } + return (string) $this->title; } /** diff --git a/lib/templates/moremenu_children.mustache b/lib/templates/moremenu_children.mustache index cc7d5b56673..65fddc1bf94 100644 --- a/lib/templates/moremenu_children.mustache +++ b/lib/templates/moremenu_children.mustache @@ -34,6 +34,7 @@