Skip to content

Commit

Permalink
MDL-41811 find out if admin tree needed in navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak authored and Rajesh Taneja committed Oct 21, 2013
1 parent 5ab32c1 commit 61bb8c9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions admin/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
$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);
Expand Down
2 changes: 2 additions & 0 deletions lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
42 changes: 40 additions & 2 deletions lib/navigationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -240,10 +242,25 @@ public function check_if_active($strength=URL_MATCH_EXACT) {
* 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;
}

/**
Expand Down Expand Up @@ -3340,7 +3357,7 @@ public function initialise() {
$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);
Expand Down Expand Up @@ -3433,6 +3450,27 @@ public function prepend($text, $url=null, $type=null, $shorttext=null, $key=null
}
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
*
Expand Down

0 comments on commit 61bb8c9

Please sign in to comment.