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

index f415aca..add775b 100644 (file)
@@ -154,17 +154,8 @@ if ($hassiteconfig) {
     }
     $ADMIN->add('filtersettings', $temp);
 
-    $activefilters = filter_get_globally_enabled();
-    $filternames = filter_get_all_installed();
-    foreach ($filternames as $filterpath => $strfiltername) {
-        if (file_exists("$CFG->dirroot/$filterpath/filtersettings.php")) {
-            $settings = new admin_settingpage('filtersetting'.str_replace('/', '', $filterpath),
-                    $strfiltername, 'moodle/site:config', !isset($activefilters[$filterpath]));
-            include("$CFG->dirroot/$filterpath/filtersettings.php");
-            if ($settings) {
-                $ADMIN->add('filtersettings', $settings);
-            }
-        }
+    foreach ($allplugins['filter'] as $filter) {
+        $filter->load_settings($ADMIN, 'filtersettings', $hassiteconfig);
     }
 
 
index 253b87c..6a6ccc7 100644 (file)
@@ -2122,14 +2122,26 @@ class plugininfo_filter extends plugininfo_base {
         return null;
     }
 
-    public function get_settings_url() {
-
+    public function get_settings_section_name() {
         $globalstates = self::get_global_states();
         $legacyname = $globalstates[$this->name]->legacyname;
-        if (filter_has_global_settings($legacyname)) {
-            return new moodle_url('/admin/settings.php', array('section' => 'filtersetting' . str_replace('/', '', $legacyname)));
-        } else {
-            return null;
+        return 'filtersetting' . str_replace('/', '', $legacyname);
+    }
+
+    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
+        $filter = $this; // also can be used inside settings.php
+
+        $settings = null;
+        if ($hassiteconfig && file_exists($this->full_path('filtersettings.php'))) {
+            $section = $this->get_settings_section_name();
+            $settings = new admin_settingpage($section, $this->displayname,
+                    'moodle/site:config', $this->is_enabled() === false);
+            include($this->full_path('filtersettings.php')); // this may also set $settings to null
+        }
+        if ($settings) {
+            $ADMIN->add($parentnodename, $settings);
         }
     }