MDL-41811 find out if admin tree needed in navigation

This commit is contained in:
Petr Škoda 2013-10-11 09:07:26 +02:00 committed by Rajesh Taneja
parent 5ab32c11b7
commit 61bb8c933f
3 changed files with 43 additions and 2 deletions

View File

@ -14,6 +14,7 @@ $PAGE->set_url('/admin/settings.php', array('section' => $section));
$PAGE->set_pagetype('admin-setting-' . $section);
$PAGE->set_pagelayout('admin');
$PAGE->navigation->clear_cache();
navigation_node::require_admin_tree();
$adminroot = admin_get_root(); // need all settings
$settingspage = $adminroot->locate($section, true);

View File

@ -6266,6 +6266,8 @@ function admin_externalpage_setup($section, $extrabutton = '', array $extraurlpa
die;
}
navigation_node::require_admin_tree();
// $PAGE->set_extra_button($extrabutton); TODO
if (!$actualurl) {

View File

@ -137,6 +137,8 @@ class navigation_node implements renderable {
protected static $fullmeurl = null;
/** @var bool toogles auto matching of active node */
public static $autofindactive = true;
/** @var bool should we load full admin tree or rely on AJAX for performance reasons */
protected static $loadadmintree = false;
/** @var mixed If set to an int, that section will be included even if it has no activities */
public $includesectionnum = false;
@ -240,10 +242,25 @@ class navigation_node implements renderable {
* is either $PAGE->url or if that hasn't been set $FULLME.
*
* @param moodle_url $url The url to use for the fullmeurl.
* @param bool $loadadmintree use true if the URL point to administration tree
*/
public static function override_active_url(moodle_url $url) {
public static function override_active_url(moodle_url $url, $loadadmintree = false) {
// Clone the URL, in case the calling script changes their URL later.
self::$fullmeurl = new moodle_url($url);
// True means we do not want AJAX loaded admin tree, required for all admin pages.
if ($loadadmintree) {
// Do not change back to false if already set.
self::$loadadmintree = true;
}
}
/**
* Use when page is linked from the admin tree,
* if not used navigation could not find the page using current URL
* because the tree is not fully loaded.
*/
public static function require_admin_tree() {
self::$loadadmintree = true;
}
/**
@ -3340,7 +3357,7 @@ class settings_navigation extends navigation_node {
$admin = false;
if (isloggedin() && !isguestuser() && (!property_exists($SESSION, 'load_navigation_admin') || $SESSION->load_navigation_admin)) {
// If admin page or user logged in, then load admin settings.
$isadminpage = ((strpos($this->page->pagetype, 'admin-') === 0) || ($this->page->pagelayout === 'admin'));
$isadminpage = $this->is_admin_tree_needed();
if ($isadminpage || !isset($SESSION->load_navigation_admin)) {
$admin = $this->load_administration_settings();
$SESSION->load_navigation_admin = ($admin->children->count() > 0);
@ -3433,6 +3450,27 @@ class settings_navigation extends navigation_node {
}
return $node;
}
/**
* Does this page require loading of full admin tree or is
* it enough rely on AJAX?
* @return bool
*/
protected function is_admin_tree_needed() {
if (self::$loadadmintree) {
return true;
}
if ($this->page->pagelayout === 'admin' or strpos($this->page->pagetype, 'admin-') === 0) {
if ($this->page->context->contextlevel >= CONTEXT_COURSE) {
debugging('Course level administration should not be attached to administration tree', DEBUG_DEVELOPER);
}
return true;
}
return false;
}
/**
* Load the site administration tree
*