Permalink
Browse files

MDL-37762: Breadcrumb not showing categories on course page

  • Loading branch information...
1 parent 931eff3 commit 7a5f3762d09f608b3c0d3023de2d3eccfb53f543 @pauln pauln committed with Sam Hemelryk Apr 12, 2013
Showing with 38 additions and 0 deletions.
  1. +38 −0 lib/navigationlib.php
View
@@ -3052,6 +3052,12 @@ public function get_items() {
if (!$navigationactivenode->mainnavonly) {
$items[] = $navigationactivenode;
}
+ if ($navigationactivenode->type === self::TYPE_COURSE && $navigationactivenode->parent->key === 'currentcourse') {
+ $categories = $this->get_course_categories();
+ foreach ($categories as $category) {
+ $items[] = $category;
+ }
+ }
$navigationactivenode = $navigationactivenode->parent;
}
} else if ($navigationactivenode) {
@@ -3060,6 +3066,12 @@ public function get_items() {
if (!$navigationactivenode->mainnavonly) {
$items[] = $navigationactivenode;
}
+ if ($navigationactivenode->type === self::TYPE_COURSE && $navigationactivenode->parent->key === 'currentcourse') {
+ $categories = $this->get_course_categories();
+ foreach ($categories as $category) {
+ $items[] = $category;
+ }
+ }
$navigationactivenode = $navigationactivenode->parent;
}
} else if ($settingsactivenode) {
@@ -3085,6 +3097,32 @@ public function get_items() {
}
/**
+ * Get the list of categories leading to this course.
+ *
+ * This function is used by {@link navbar::get_items()} to add back the "courses"
+ * node and category chain leading to the current course. Note that this is only ever
+ * called for the current course, so we don't need to bother taking in any parameters.
+ *
+ * @return array
+ */
+ private function get_course_categories() {
+ $categories = array();
+ $id = $this->page->course->category;
+ while ($id) {
+ $category = coursecat::get($id);
+ $categories[] = new navigation_node(array(
+ 'text'=>$category->name,
+ 'shorttext'=>$category->name,
+ 'key'=>$category->idnumber,
+ 'action'=>new moodle_url('/course/category.php', array('id'=>$id))
+ ));
+ $id = $category->parent;
+ }
+ $categories[] = $this->page->navigation->get('courses');
+ return $categories;
+ }
+
+ /**
* Add a new navigation_node to the navbar, overrides parent::add
*
* This function overrides {@link navigation_node::add()} so that we can change

0 comments on commit 7a5f376

Please sign in to comment.