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:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user