MDL-34250 navigation: Always look for correct parent context.
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 28 Aug 2012 18:37:46 +0000 (20:37 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 28 Aug 2012 18:41:21 +0000 (20:41 +0200)
Conflicts:
lib/navigationlib.php

lib/navigationlib.php

index 92f9029..84ca77f 100644 (file)
@@ -1131,7 +1131,13 @@ class global_navigation extends navigation_node {
                     $addedcategories[$category->id] = $categoryparent->add($category->name, $url, self::TYPE_CATEGORY, $category->name, $category->id);
 
                     if (!$category->visible) {
-                        if (!has_capability('moodle/category:viewhiddencategories', get_context_instance(CONTEXT_COURSECAT, $category->parent))) {
+                        // Let's decide the context where viewhidden cap checks will happen.
+                        if ($category->parent == '0') {
+                            $contexttocheck = context_system::instance();
+                        } else {
+                            $contexttocheck = context_coursecat::instance($category->parent);
+                        }
+                        if (!has_capability('moodle/category:viewhiddencategories', $contexttocheck)) {
                             $addedcategories[$category->id]->display = false;
                         } else {
                             $addedcategories[$category->id]->hidden = true;