From 8968b51c6b734308c03fb0067b4ebf698c042108 Mon Sep 17 00:00:00 2001
From: Mihail Geshoski <mihail@moodle.com>
Date: Thu, 10 Feb 2022 13:26:58 +0800
Subject: [PATCH] MDL-73645 core_enrol: Update breadcrumb nodes

---
 enrol/editinstance.php | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/enrol/editinstance.php b/enrol/editinstance.php
index 8fcc61c0ed8..2363340f918 100644
--- a/enrol/editinstance.php
+++ b/enrol/editinstance.php
@@ -40,7 +40,8 @@ if (!$plugin) {
 require_login($course);
 require_capability('enrol/' . $type . ':config', $context);
 
-$PAGE->set_url('/enrol/editinstance.php', array('courseid' => $course->id, 'id' => $instanceid, 'type' => $type));
+$url = new moodle_url('/enrol/editinstance.php', ['courseid' => $course->id, 'id' => $instanceid, 'type' => $type]);
+$PAGE->set_url($url);
 $PAGE->set_pagelayout('admin');
 $PAGE->set_docs_path('enrol/' . $type . '/edit');
 
@@ -54,6 +55,11 @@ if (!enrol_is_enabled($type)) {
 
 if ($instanceid) {
     $instance = $DB->get_record('enrol', array('courseid' => $course->id, 'enrol' => $type, 'id' => $instanceid), '*', MUST_EXIST);
+    if ($instance->status == ENROL_INSTANCE_DISABLED) { // The instance is currently disabled.
+        navigation_node::override_active_url(new moodle_url('/enrol/instances.php', ['id' => $course->id]));
+        $name = $instance->name ?: get_string('pluginname', 'enrol_' . $type);
+        $PAGE->navbar->add($name, $url);
+    }
 
 } else {
     require_capability('moodle/course:enrolconfig', $context);
@@ -64,6 +70,7 @@ if ($instanceid) {
     $instance->id       = null;
     $instance->courseid = $course->id;
     $instance->status   = ENROL_INSTANCE_ENABLED; // Do not use default for automatically created instances here.
+    $PAGE->navbar->add(get_string('pluginname', 'enrol_' . $type), $url);
 }
 
 $mform = new enrol_instance_edit_form(null, array($instance, $plugin, $context, $type, $return));