MDL-35661 Loading of plugin settings for enrol plugins (plugininfo_enrol)
authorMarina Glancy <marina@moodle.com>
Wed, 19 Sep 2012 01:20:58 +0000 (09:20 +0800)
committerMarina Glancy <marina@moodle.com>
Tue, 9 Oct 2012 01:57:57 +0000 (09:57 +0800)
admin/settings/plugins.php
enrol/imsenterprise/settings.php
lib/pluginlib.php

index 5ea1660..6d8f95a 100644 (file)
@@ -81,28 +81,10 @@ if ($hassiteconfig) {
     $ADMIN->add('modules', new admin_category('enrolments', new lang_string('enrolments', 'enrol')));
     $temp = new admin_settingpage('manageenrols', new lang_string('manageenrols', 'enrol'));
     $temp->add(new admin_setting_manageenrols());
-    if (empty($CFG->enrol_plugins_enabled)) {
-        $enabled = array();
-    } else {
-        $enabled = explode(',', $CFG->enrol_plugins_enabled);
-    }
-    $enrols = get_plugin_list('enrol');
     $ADMIN->add('enrolments', $temp);
-    foreach($enrols as $enrol=>$enrolpath) {
-        if (!file_exists("$enrolpath/settings.php")) {
-            continue;
-        }
-
-        $settings = new admin_settingpage('enrolsettings'.$enrol, new lang_string('pluginname', 'enrol_'.$enrol), 'moodle/site:config', !in_array($enrol, $enabled));
-        // settings.php may create a subcategory or unset the settings completely
-        include("$enrolpath/settings.php");
-        if ($settings) {
-            $ADMIN->add('enrolments', $settings);
-        }
-
+    foreach($allplugins['enrol'] as $enrol) {
+        $enrol->load_settings($ADMIN, 'enrolments', $hassiteconfig);
     }
-    unset($enabled);
-    unset($enrols);
 
 
 /// Editor plugins
index 9040b21..1c7f205 100644 (file)
@@ -27,7 +27,7 @@
 defined('MOODLE_INTERNAL') || die();
 
 if ($ADMIN->fulltree) {
-    require_once('locallib.php');
+    require_once($CFG->dirroot.'/enrol/imsenterprise/locallib.php');
 
     $settings->add(new admin_setting_heading('enrol_imsenterprise_settings', '', get_string('pluginname_desc', 'enrol_imsenterprise')));
 
index 45de46c..c0a5884 100644 (file)
@@ -2445,12 +2445,24 @@ class plugininfo_enrol extends plugininfo_base {
         return isset($enabled[$this->name]);
     }
 
-    public function get_settings_url() {
+    public function get_settings_section_name() {
+        return 'enrolsettings' . $this->name;
+    }
 
-        if ($this->is_enabled() or file_exists($this->full_path('settings.php'))) {
-            return new moodle_url('/admin/settings.php', array('section' => 'enrolsettings' . $this->name));
-        } else {
-            return parent::get_settings_url();
+    public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) {
+        global $CFG, $USER, $DB, $OUTPUT, $PAGE; // in case settings.php wants to refer to them
+        $ADMIN = $adminroot; // may be used in settings.php
+        $enrol = $this; // also can be used inside settings.php
+        $section = $this->get_settings_section_name();
+
+        $settings = null;
+        if ($hassiteconfig && file_exists($this->full_path('settings.php'))) {
+            $settings = new admin_settingpage($section, $this->displayname,
+                    'moodle/site:config', $this->is_enabled() === false);
+            include($this->full_path('settings.php')); // this may also set $settings to null
+        }
+        if ($settings) {
+            $ADMIN->add($parentnodename, $settings);
         }
     }