Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-37762: Breadcrumb not showing categories on course page

  • Loading branch information...
commit 75bdae9f6e8b4da517d0be785ce8623140a7e7a1 1 parent b3661ab
@pauln pauln authored
Showing with 38 additions and 0 deletions.
  1. +38 −0 lib/navigationlib.php
View
38 lib/navigationlib.php
@@ -3007,6 +3007,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) {
@@ -3015,6 +3021,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) {
@@ -3040,6 +3052,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
Please sign in to comment.
Something went wrong with that request. Please try again.