From 155fffe6a4db4dc16d7dad86e7988a39f977c1b7 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Tue, 5 Jul 2011 10:13:14 +0200 Subject: [PATCH] MDL-28168 Improved custom_menu constructor This improves custom_menu constructor by dropping support for useless $text parameter and replacing it with the menu definition. This makes custom_menu instance independent on the place where the menu is defined ($CFG->custommenuitems) and can be unit-tested. Also, multiple instances of custom_menu can be instantiated now which can be interesting in the future. --- lib/outputcomponents.php | 14 ++++++++------ lib/outputrenderers.php | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index 7cea429543a..e0a02cbcda7 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -2323,15 +2323,17 @@ class custom_menu_item implements renderable { * @since Moodle 2.0 */ class custom_menu extends custom_menu_item { + /** * Creates the custom menu - * @param string $text Sets the text for this custom menu, never gets used and is optional + * + * @param string $definition the menu items definition in syntax required by {@link convert_text_to_menu_nodes()} */ - public function __construct($text='base') { - global $CFG; - parent::__construct($text); - if (!empty($CFG->custommenuitems)) { - $this->override_children(self::convert_text_to_menu_nodes($CFG->custommenuitems)); + public function __construct($definition = '') { + + parent::__construct('root'); // create virtual root element of the menu + if (!empty($definition)) { + $this->override_children(self::convert_text_to_menu_nodes($definition)); } } diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 9f2bb835d78..c54f16a84a5 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -2410,7 +2410,7 @@ EOD; if (empty($CFG->custommenuitems)) { return ''; } - $custommenu = new custom_menu(); + $custommenu = new custom_menu($CFG->custommenuitems); return $this->render_custom_menu($custommenu); }