MDL-49620 availability: plugins can have global settings

This commit is contained in:
Davo Smith 2016-02-04 15:21:02 +00:00
parent 9d5d9c64ff
commit 6badbf0135

View File

@ -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);
}
}
}