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.
This commit is contained in:
David Mudrak
2011-07-07 11:30:03 +02:00
parent 153a13226e
commit 155fffe6a4
2 changed files with 9 additions and 7 deletions
+8 -6
View File
@@ -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));
}
}