#213 Allow element plugins to have admin settings

This commit is contained in:
Dmitrii Metelkin 2018-07-17 16:49:26 +10:00 committed by Mark Nelson
parent 928e70d5e7
commit 2731008401
3 changed files with 57 additions and 0 deletions

View file

@ -44,4 +44,44 @@ class customcertelement extends base {
public function is_uninstall_allowed() { public function is_uninstall_allowed() {
return false; return false;
} }
/**
* Loads plugin settings to the settings tree.
*
* @param \part_of_admin_tree $adminroot
* @param string $parentnodename
* @param bool $hassiteconfig whether the current user has moodle/site:config capability
*/
public function load_settings(\part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) {
global $CFG, $USER, $DB, $OUTPUT, $PAGE;
$ADMIN = $adminroot;
$plugininfo = $this;
if (!$this->is_installed_and_upgraded()) {
return;
}
if (!$hassiteconfig or !file_exists($this->full_path('settings.php'))) {
return;
}
$section = $this->get_settings_section_name();
$settings = new \admin_settingpage($section, $this->displayname, 'moodle/site:config', false);
include($this->full_path('settings.php'));
$ADMIN->add($parentnodename, $settings);
}
/**
* Get the settings section name.
*
* @return null|string the settings section name.
*/
public function get_settings_section_name() {
if (file_exists($this->full_path('settings.php'))) {
return 'customcertelement_' . $this->name;
} else {
return null;
}
}
} }

View file

@ -40,6 +40,7 @@ $string['customcert:viewreport'] = 'View course report';
$string['customcert:viewallcertificates'] = 'View all certificates'; $string['customcert:viewallcertificates'] = 'View all certificates';
$string['customcert:verifyallcertificates'] = 'Verify all certificates on the site'; $string['customcert:verifyallcertificates'] = 'Verify all certificates on the site';
$string['customcert:verifycertificate'] = 'Verify a certificate'; $string['customcert:verifycertificate'] = 'Verify a certificate';
$string['customcertsettings'] = 'Custom certificate settings';
$string['deletecertpage'] = 'Delete page'; $string['deletecertpage'] = 'Delete page';
$string['deleteconfirm'] = 'Delete confirmation'; $string['deleteconfirm'] = 'Delete confirmation';
$string['deleteelement'] = 'Delete element'; $string['deleteelement'] = 'Delete element';
@ -57,6 +58,7 @@ $string['editelement'] = 'Edit element';
$string['edittemplate'] = 'Edit template'; $string['edittemplate'] = 'Edit template';
$string['elementname'] = 'Element name'; $string['elementname'] = 'Element name';
$string['elementname_help'] = 'This will be the name used to identify this element when editing a certificate. Note: this will not displayed on the PDF.'; $string['elementname_help'] = 'This will be the name used to identify this element when editing a certificate. Note: this will not displayed on the PDF.';
$string['elementplugins'] = 'Element plugins';
$string['elements'] = 'Elements'; $string['elements'] = 'Elements';
$string['elements_help'] = 'This is the list of elements that will be displayed on the certificate. $string['elements_help'] = 'This is the list of elements that will be displayed on the certificate.

View file

@ -25,6 +25,10 @@
defined('MOODLE_INTERNAL') || die; defined('MOODLE_INTERNAL') || die;
$url = $CFG->wwwroot . '/mod/customcert/verify_certificate.php'; $url = $CFG->wwwroot . '/mod/customcert/verify_certificate.php';
$ADMIN->add('modsettings', new admin_category('customcert', get_string('pluginname', 'mod_customcert')));
$settings = new admin_settingpage('modsettingcustomcert', new lang_string('customcertsettings', 'mod_customcert'));
$settings->add(new admin_setting_configcheckbox('customcert/verifyallcertificates', $settings->add(new admin_setting_configcheckbox('customcert/verifyallcertificates',
get_string('verifyallcertificates', 'customcert'), get_string('verifyallcertificates', 'customcert'),
get_string('verifyallcertificates_desc', 'customcert', $url), get_string('verifyallcertificates_desc', 'customcert', $url),
@ -46,3 +50,14 @@ $settings->add(new \mod_customcert\admin_setting_link('customcert/managetemplate
$settings->add(new \mod_customcert\admin_setting_link('customcert/uploadimage', $settings->add(new \mod_customcert\admin_setting_link('customcert/uploadimage',
get_string('uploadimage', 'customcert'), get_string('uploadimagedesc', 'customcert'), get_string('uploadimage', 'customcert'), get_string('uploadimagedesc', 'customcert'),
get_string('uploadimage', 'customcert'), new moodle_url('/mod/customcert/upload_image.php'), '')); get_string('uploadimage', 'customcert'), new moodle_url('/mod/customcert/upload_image.php'), ''));
$ADMIN->add('customcert', $settings);
// Element plugin settings.
$ADMIN->add('customcert', new admin_category('customcertelements', get_string('elementplugins', 'customcert')));
$plugins = \core_plugin_manager::instance()->get_plugins_of_type('customcertelement');
foreach ($plugins as $plugin) {
$plugin->load_settings($ADMIN, 'customcertelements', $hassiteconfig);
}
// Tell core we already added the settings structure.
$settings = null;