mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
Merge branch 'MDL-76099-master' of https://github.com/stevandoMoodle/moodle
This commit is contained in:
commit
f865b326ca
@ -48,6 +48,7 @@ $PAGE->set_title($title);
|
||||
$PAGE->set_heading($title);
|
||||
$PAGE->set_secondary_active_tab('coursereuse');
|
||||
$PAGE->requires->js_call_amd('core_backup/async_backup', 'asyncCopyAllStatus');
|
||||
$PAGE->secondarynav->set_overflow_selected_node('copy');
|
||||
|
||||
// Build the page output.
|
||||
echo $OUTPUT->header();
|
||||
|
@ -53,6 +53,8 @@ $PAGE->set_secondary_active_tab('coursereuse');
|
||||
require_login($course, null, $cm);
|
||||
require_capability('moodle/restore:restorecourse', $context);
|
||||
|
||||
$PAGE->secondarynav->set_overflow_selected_node('restore');
|
||||
|
||||
if (is_null($course)) {
|
||||
$coursefullname = $SITE->fullname;
|
||||
$courseshortname = $SITE->shortname;
|
||||
|
@ -41,6 +41,9 @@ class secondary extends view {
|
||||
/** @var navigation_node The course overflow node. */
|
||||
protected $courseoverflownode = null;
|
||||
|
||||
/** @var string The key of the node to set as selected in the course overflow menu, if explicitly set by a page. */
|
||||
protected $overflowselected = null;
|
||||
|
||||
/**
|
||||
* Defines the default structure for the secondary nav in a course context.
|
||||
*
|
||||
@ -522,6 +525,55 @@ class secondary extends view {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively search a node and its children for a node matching the key string $key.
|
||||
*
|
||||
* @param navigation_node $node the navigation node to check.
|
||||
* @param string $key the key of the node to match.
|
||||
* @return navigation_node|null node if found, otherwise null.
|
||||
*/
|
||||
protected function node_matches_key_string(navigation_node $node, string $key): ?navigation_node {
|
||||
if ($node->has_action()) {
|
||||
// Check this node first.
|
||||
if ($node->key == $key) {
|
||||
return $node;
|
||||
}
|
||||
}
|
||||
if ($node->has_children()) {
|
||||
foreach ($node->children as $child) {
|
||||
$result = $this->node_matches_key_string($child, $key);
|
||||
if ($result) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force a specific node in the 'coursereuse' course overflow to be selected, based on the provided node key.
|
||||
*
|
||||
* Normally, the selected node is determined by matching the page URL to the node URL. E.g. The page 'backup/restorefile.php'
|
||||
* will match the "Restore" node which has a registered URL of 'backup/restorefile.php' because the URLs match.
|
||||
*
|
||||
* This method allows a page to choose a specific node to match, which is useful in cases where the page knows its URL won't
|
||||
* match the node it needs to reside under. I.e. this permits several pages to 'share' the same overflow node. When the page
|
||||
* knows the PAGE->url won't match the node URL, the page can simply say "I want to match the 'XXX' node".
|
||||
*
|
||||
* E.g.
|
||||
* - The $PAGE->url is 'backup/restore.php' (this page is used during restores but isn't the main landing page for a restore)
|
||||
* - The 'Restore' node in the overflow has a key of 'restore' and will only match 'backup/restorefile.php' by default (the
|
||||
* main restore landing page).
|
||||
* - The backup/restore.php page calls:
|
||||
* $PAGE->secondarynav->set_overflow_selected_node(new moodle_url('restore');
|
||||
* and when the page is loaded, the 'Restore' node be presented as the selected node.
|
||||
*
|
||||
* @param string $nodekey The string key of the overflow node to match.
|
||||
*/
|
||||
public function set_overflow_selected_node(string $nodekey): void {
|
||||
$this->overflowselected = $nodekey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a url_select object with overflow navigation nodes.
|
||||
* This looks to see if the current page is within the course administration, or some other page that requires an overflow
|
||||
@ -578,7 +630,13 @@ class secondary extends view {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
$menuselect = new url_select($menuarray, $this->page->url, null);
|
||||
// If the page has explicitly set the overflow node it would like selected, find and use that node.
|
||||
if ($this->overflowselected) {
|
||||
$selectedoverflownode = $this->node_matches_key_string($courseoverflownode, $this->overflowselected);
|
||||
$selectedoverflownodeurl = $selectedoverflownode ? $selectedoverflownode->action->out(false) : null;
|
||||
}
|
||||
|
||||
$menuselect = new url_select($menuarray, $selectedoverflownodeurl ?? $this->page->url, null);
|
||||
$menuselect->set_label(get_string('browsecourseadminindex', 'course'), ['class' => 'sr-only']);
|
||||
return $menuselect;
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user