diff --git a/lib/classes/plugininfo/availability.php b/lib/classes/plugininfo/availability.php index 1444effe28d..1059ec5dbc9 100644 --- a/lib/classes/plugininfo/availability.php +++ b/lib/classes/plugininfo/availability.php @@ -23,6 +23,8 @@ */ namespace core\plugininfo; +use admin_settingpage; + defined('MOODLE_INTERNAL') || die(); /** @@ -62,4 +64,46 @@ class availability extends base { public function is_uninstall_allowed() { return true; } + + /** + * Get the name for the settings section. + * + * @return string + */ + public function get_settings_section_name() { + return 'availabilitysetting' . $this->name; + } + + /** + * Load the global settings for a particular availability plugin (if there are any) + * + * @param \part_of_admin_tree $adminroot + * @param string $parentnodename + * @param bool $hassiteconfig + */ + 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. + $plugininfo = $this; // Also can be used inside settings.php + $availability = $this; // Also to be used inside settings.php. + + if (!$this->is_installed_and_upgraded()) { + return; + } + + if (!$hassiteconfig) { + return; + } + + $section = $this->get_settings_section_name(); + + $settings = null; + if (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); + } + } }