MDL-71901 core: Allow blocks to specify their own nav
- Part of: MDL-69588
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace core_block\local\views;
|
||||
|
||||
/**
|
||||
* Class secondary
|
||||
*
|
||||
* @package core_block
|
||||
* @category navigation
|
||||
*/
|
||||
class secondary extends \core\navigation\views\secondary {
|
||||
/**
|
||||
* Blocks don't require secondary navs as they can be accessed from multiple places and in different contexts.
|
||||
*/
|
||||
public function initialise(): void {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1520,6 +1520,7 @@ class block_manager {
|
||||
$deleteurlparams = $this->page->url->params();
|
||||
$deletepage->set_url($deleteurlbase, $deleteurlparams);
|
||||
$deletepage->set_block_actions_done();
|
||||
$deletepage->set_secondarynav($this->get_secondarynav($block));
|
||||
// At this point we are either going to redirect, or display the form, so
|
||||
// overwrite global $PAGE ready for this. (Formslib refers to it.)
|
||||
$PAGE = $deletepage;
|
||||
@@ -1608,6 +1609,23 @@ class block_manager {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function to check whether a block is implementing a secondary nav class and return it
|
||||
* initialised to the calling function
|
||||
*
|
||||
* @param block_base $block
|
||||
* @return \core\navigation\views\secondary
|
||||
*/
|
||||
protected function get_secondarynav(block_base $block): \core\navigation\views\secondary {
|
||||
$class = "core_block\\local\\views\\secondary";
|
||||
if (class_exists("block_{$block->name()}\\local\\views\\secondary")) {
|
||||
$class = "block_{$block->name()}\\local\\views\\secondary";
|
||||
}
|
||||
$secondarynav = new $class($this->page);
|
||||
$secondarynav->initialise();
|
||||
return $secondarynav;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle showing/processing the submission from the block editing form.
|
||||
* @return boolean true if the form was submitted and the new config saved. Does not
|
||||
@@ -1635,6 +1653,8 @@ class block_manager {
|
||||
$editpage->set_course($this->page->course);
|
||||
//$editpage->set_context($block->context);
|
||||
$editpage->set_context($this->page->context);
|
||||
$editpage->set_secondarynav($this->get_secondarynav($block));
|
||||
|
||||
if ($this->page->cm) {
|
||||
$editpage->set_cm($this->page->cm);
|
||||
}
|
||||
|
||||
@@ -202,8 +202,8 @@ class secondary extends view {
|
||||
$this->add(get_string('coursepage', 'admin'), $url, self::TYPE_COURSE, null, 'coursehome');
|
||||
|
||||
$nodes = $this->get_default_course_mapping();
|
||||
$nodesordered = $this->get_leaf_nodes($settingsnav, $nodes['settings']);
|
||||
$nodesordered += $this->get_leaf_nodes($navigation, $nodes['navigation']);
|
||||
$nodesordered = $this->get_leaf_nodes($settingsnav, $nodes['settings'] ?? []);
|
||||
$nodesordered += $this->get_leaf_nodes($navigation, $nodes['navigation'] ?? []);
|
||||
$this->add_ordered_nodes($nodesordered);
|
||||
|
||||
// All additional nodes will be available under the 'Course admin' page.
|
||||
|
||||
@@ -1270,6 +1270,14 @@ class moodle_page {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Force set secondary_nav. Useful in cases where we dealing with non course modules. e.g. blocks, tools.
|
||||
* @param secondary $nav
|
||||
*/
|
||||
public function set_secondarynav(secondary $nav) {
|
||||
$this->_secondarynav = $nav;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a CSS class to the body tag of the page.
|
||||
*
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2021082000.01; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2021082000.02; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
$release = '4.0dev (Build: 20210820)'; // Human-friendly version name
|
||||
|
||||
Reference in New Issue
Block a user