MDL-73393 navigation: Reintroduce nav-drawer and add a button

- Reintroduce nav components to have backwards compatibility with existing themes
- Mark for deprecation flat_navigation and flat_navigation_node
This commit is contained in:
Peter Dias 2022-03-03 15:12:20 +08:00
parent 34ce1463cc
commit 0a7b8dbc46
6 changed files with 37 additions and 5 deletions

View File

@ -444,11 +444,13 @@ class navigation_node implements renderable {
/**
* Walk the tree building up a list of all the flat navigation nodes.
*
* @deprecated since Moodle 4.0
* @param flat_navigation $nodes List of the found flat navigation nodes.
* @param boolean $showdivider Show a divider before the first node.
* @param string $label A label for the collection of navigation links.
*/
public function build_flat_navigation_list(flat_navigation $nodes, $showdivider = false, $label = '') {
debugging("Function has been deprecated with the deprecation of the flat_navigation class.");
if ($this->showinflatnavigation) {
$indent = 0;
if ($this->type == self::TYPE_COURSE || $this->key === self::COURSE_INDEX_PAGE) {
@ -3981,6 +3983,7 @@ class breadcrumb_navigation_node extends navigation_node {
* Subclass of navigation_node allowing different rendering for the flat navigation
* in particular allowing dividers and indents.
*
* @deprecated since Moodle 4.0 - do not use any more. Leverage secondary/tertiary navigation concepts
* @package core
* @category navigation
* @copyright 2016 Damyon Wiese
@ -4003,6 +4006,7 @@ class flat_navigation_node extends navigation_node {
* @param mixed $navnode A navigation_node or an array
*/
public function __construct($navnode, $indent) {
debugging("Flat nav has been deprecated in favour of primary/secondary navigation concepts");
if (is_array($navnode)) {
parent::__construct($navnode);
} else if ($navnode instanceof navigation_node) {
@ -4114,6 +4118,7 @@ class flat_navigation_node extends navigation_node {
* Class used to generate a collection of navigation nodes most closely related
* to the current page.
*
* @deprecated since Moodle 4.0 - do not use any more. Leverage secondary/tertiary navigation concepts
* @package core
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
@ -4131,6 +4136,7 @@ class flat_navigation extends navigation_node_collection {
if (during_initial_install()) {
return false;
}
debugging("Flat navigation has been deprecated in favour of primary/secondary navigation concepts");
$this->page = $page;
}
@ -4208,6 +4214,24 @@ class flat_navigation extends navigation_node_collection {
$flat->icon = new pix_icon('t/preferences', '');
$this->add($flat);
}
// Add-a-block in editing mode.
if (isset($this->page->theme->addblockposition) &&
$this->page->theme->addblockposition == BLOCK_ADDBLOCK_POSITION_FLATNAV &&
$PAGE->user_is_editing() && $PAGE->user_can_edit_blocks()) {
$url = new moodle_url($PAGE->url, ['bui_addblock' => '', 'sesskey' => sesskey()]);
$addablock = navigation_node::create(get_string('addblock'), $url);
$flat = new flat_navigation_node($addablock, 0);
$flat->set_showdivider(true, get_string('blocksaddedit'));
$flat->key = 'addblock';
$flat->icon = new pix_icon('i/addblock', '');
$this->add($flat);
$addblockurl = "?{$url->get_query_string(false)}";
$PAGE->requires->js_call_amd('core/addblockmodal', 'init',
[$PAGE->pagetype, $PAGE->pagelayout, $addblockurl]);
}
}
/**

View File

@ -251,6 +251,7 @@ value to get the list of blocks that won't be displayed for a theme.
* The parameter $modinfo of the get_data method in completion_info class has been deprecated and is not used anymore.
* A new method, get_default_home_page(), has been added to moodlelib to get the default home page to display if current one is not
defined or can't be applied.
* Flat navigation classes have been marked for deprecation with the introduction of primary and secondary navigation concepts.
=== 3.11.4 ===
* A new option dontforcesvgdownload has been added to the $options parameter of the send_file() function.

View File

@ -74,6 +74,5 @@ $templatecontext = [
'overflow' => $overflow,
'addblockbutton' => $addblockbutton,
];
$nav = $PAGE->flatnav;
$templatecontext['firstcollectionlabel'] = $nav->get_collectionlabel();
echo $OUTPUT->render_from_template('theme_boost/columns2', $templatecontext);

View File

@ -108,7 +108,4 @@ $templatecontext = [
'addblockbutton' => $addblockbutton
];
$nav = $PAGE->flatnav;
$templatecontext['firstcollectionlabel'] = $nav->get_collectionlabel();
echo $OUTPUT->render_from_template('theme_boost/drawers', $templatecontext);

View File

@ -15,6 +15,7 @@
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@deprecated since Moodle 4.0
@template theme_boost/flat_navigation
Display the flat navigation for the boost theme

View File

@ -0,0 +1,10 @@
{{!
@deprecated since 4.0
@template theme_boost/nav-drawer
Example context (json): {}
}}
<div id="nav-drawer" data-region="drawer" class="d-print-none moodle-has-zindex {{^navdraweropen}}closed{{/navdraweropen}}" aria-hidden="{{#navdraweropen}}false{{/navdraweropen}}{{^navdraweropen}}true{{/navdraweropen}}" tabindex="-1">
{{> theme_boost/flat_navigation }}
</div>