Skip to content

Commit

Permalink
MDL-44902: Update admin settings support for ltisource plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
polothy committed May 21, 2014
1 parent d3496e3 commit e9033d1
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 36 deletions.
43 changes: 41 additions & 2 deletions mod/lti/classes/plugininfo/ltisource.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,50 @@
*/
namespace mod_lti\plugininfo;

use core\plugininfo\base, core_plugin_manager, moodle_url;
use core\plugininfo\base;

defined('MOODLE_INTERNAL') || die();


class ltisource extends base {
// Accept base class implementation 100%.
/**
* Returns the node name used in admin settings menu for this plugin settings (if applicable)
*
* @return null|string node name or null if plugin does not create settings node (default)
*/
public function get_settings_section_name() {
return 'ltisourcesetting'.$this->name;
}

/**
* Loads plugin settings to the settings tree
*
* This function usually includes settings.php file in plugins folder.
* Alternatively it can create a link to some settings page (instance of admin_externalpage)
*
* @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; // 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.

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', $this->is_enabled() === false);

include($this->full_path('settings.php')); // This may also set $settings to null.

if ($settings) {
$ADMIN->add($parentnodename, $settings);
}
}
}
1 change: 1 addition & 0 deletions mod/lti/lang/en/lti.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@
$string['lti:manage'] = 'Be an Instructor when the tool is launched';
$string['lti:requesttooladd'] = 'Request a tool is configured site-wide';
$string['lti:view'] = 'Launch external tool activities';
$string['ltisettings'] = 'LTI settings';
$string['lti_administration'] = 'LTI Administration';
$string['lti_errormsg'] = 'The tool returned the following error message: "{$a}"';
$string['lti_launch_error'] = 'An error occurred when launching the external tool:';
Expand Down
55 changes: 21 additions & 34 deletions mod/lti/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@

defined('MOODLE_INTERNAL') || die;

/** @var admin_settingpage $settings */
$modltifolder = new admin_category('modltifolder', new lang_string('pluginname', 'mod_lti'), $module->is_enabled() === false);
$ADMIN->add('modsettings', $modltifolder);

$ADMIN->add('modltifolder', $settings);

foreach (core_plugin_manager::instance()->get_plugins_of_type('ltisource') as $plugin) {
/** @var \mod_lti\plugininfo\ltisource $plugin */
$plugin->load_settings($ADMIN, 'modltifolder', $hassiteconfig);
}

if ($ADMIN->fulltree) {
require_once($CFG->dirroot.'/mod/lti/locallib.php');

Expand Down Expand Up @@ -172,40 +183,16 @@
//]]
</script>
";
$settings->add(new admin_setting_heading('lti_types', get_string('external_tool_types', 'lti') . $OUTPUT->help_icon('main_admin', 'lti'), $template));

if (!during_initial_install()) {
// Process subplugin settings pages if any.
// Every subplugin that wishes to have settings page should provide it's own
// settings.php assuming it will be added as a custom settings page.
// A type will be passed through subtype parameter.
// All such links will be placed in separate category called LTI.
$plugins = get_plugin_list('ltisource');
if (!empty($plugins)) {
$toadd = array();
foreach ($plugins as $name => $path) {
if (file_exists($path.DIRECTORY_SEPARATOR.'settings.php')) {
$toadd[] = $name;
}
}
$settings->add(new admin_setting_heading('lti_types', new lang_string('external_tool_types', 'lti') . $OUTPUT->help_icon('main_admin', 'lti'), $template));
}

if (!empty($toadd)) {
$ADMIN->add('modules',
new admin_category('ltisource',
new lang_string('lti', 'lti'),
$module->is_enabled() === false)
);
if (count($modltifolder->children) <= 1) {
// No need for a folder, revert to default activity settings page.
$ADMIN->prune('modltifolder');
} else {
// Using the folder, update settings name.
$settings->visiblename = new lang_string('ltisettings', 'mod_lti');

foreach ($toadd as $name) {
$component = 'ltisource_'.$name;
$ADMIN->add($component,
new admin_externalpage($name,
new lang_string('pluginname', $component),
new moodle_url("/mod/lti/source/{$name}/settings.php",
array('subtype' => $component)))
);
}
}
}
}
// Tell core we already added the settings structure.
$settings = null;
}

0 comments on commit e9033d1

Please sign in to comment.