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

index 74b1f29..5ea1660 100644 (file)
@@ -73,27 +73,10 @@ if ($hassiteconfig) {
     $temp->add(new admin_setting_configtext('recaptchaprivatekey', new lang_string('recaptchaprivatekey', 'admin'), new lang_string('configrecaptchaprivatekey', 'admin'), '', PARAM_NOTAGS));
     $ADMIN->add('authsettings', $temp);
 
-
-    $auths = get_plugin_list('auth');
-    $authsenabled = get_enabled_auth_plugins();
-    foreach ($auths as $authname => $authdir) {
-        $strauthname = new lang_string('pluginname', "auth_{$authname}");
-        // do not show disabled auths in tree, keep only settings link on manage page
-        $enabled = in_array($authname, $authsenabled);
-        if (file_exists($authdir.'/settings.php')) {
-            // TODO: finish implementation of common settings - locking, etc.
-            $settings = new admin_settingpage('authsetting'.$authname, $strauthname, 'moodle/site:config', !$enabled);
-            include($authdir.'/settings.php');
-            if ($settings) {
-                $ADMIN->add('authsettings', $settings);
-            }
-
-        } else {
-            $ADMIN->add('authsettings', new admin_externalpage('authsetting'.$authname, $strauthname, "$CFG->wwwroot/$CFG->admin/auth_config.php?auth=$authname", 'moodle/site:config', !$enabled));
-        }
+    foreach ($allplugins['auth'] as $auth) {
+        $auth->load_settings($ADMIN, 'authsettings', $hassiteconfig);
     }
 
-
     // Enrolment plugins
     $ADMIN->add('modules', new admin_category('enrolments', new lang_string('enrolments', 'enrol')));
     $temp = new admin_settingpage('manageenrols', new lang_string('manageenrols', 'enrol'));
index 7af0e85..45de46c 100644 (file)
@@ -2393,11 +2393,31 @@ class plugininfo_auth extends plugininfo_base {
         return isset($enabled[$this->name]);
     }
 
-    public function get_settings_url() {
-        if (file_exists($this->full_path('settings.php'))) {
-            return new moodle_url('/admin/settings.php', array('section' => 'authsetting' . $this->name));
-        } else {
-            return new moodle_url('/admin/auth_config.php', array('auth' => $this->name));
+    public function get_settings_section_name() {
+        return 'authsetting' . $this->name;
+    }
+
+    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
+        $auth = $this; // also to be used inside settings.php
+        $section = $this->get_settings_section_name();
+
+        $settings = null;
+        if ($hassiteconfig) {
+            if (file_exists($this->full_path('settings.php'))) {
+                // TODO: finish implementation of common settings - locking, etc.
+                $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
+            } else {
+                $settingsurl = new moodle_url('/admin/auth_config.php', array('auth' => $this->name));
+                $settings = new admin_externalpage($section, $this->displayname,
+                        $settingsurl, 'moodle/site:config', $this->is_enabled() === false);
+            }
+        }
+        if ($settings) {
+            $ADMIN->add($parentnodename, $settings);
         }
     }
 }