Commit 3c88a678 authored by Damyon Wiese's avatar Damyon Wiese
Browse files

MDL-37459 admin: Admin settings flags

Make "Advanced" and "Lockable" flags for any admin setting.
parent a3f92b2e
......@@ -520,6 +520,10 @@ $CFG->admin = 'admin';
// Example:
// $CFG->forced_plugin_settings = array('pluginname' => array('settingname' => 'value', 'secondsetting' => 'othervalue'),
// 'otherplugin' => array('mysetting' => 'myvalue', 'thesetting' => 'thevalue'));
// Module default settings with advanced/locked checkboxes can be set too. To do this, add
// an extra config with '_adv' or '_locked' as a suffix and set the value to true or false.
// Example:
// $CFG->forced_plugin_settings = array('pluginname' => array('settingname' => 'value', 'settingname_locked' => true, 'settingname_adv' => true));
//
//=========================================================================
// 9. PHPUNIT SUPPORT
......
......@@ -864,6 +864,59 @@ abstract class moodleform_mod extends moodleform {
$mform->setType('buttonar', PARAM_RAW);
$mform->closeHeaderBefore('buttonar');
}
/**
* Get the list of admin settings for this module and apply any defaults/advanced/locked settings.
*
* @param $datetimeoffsets array - If passed, this is an array of fieldnames => times that the
* default date/time value should be relative to. If not passed, all
* date/time fields are set relative to the users current midnight.
* @return void
*/
function apply_admin_defaults($datetimeoffsets = array()) {
global $OUTPUT;
$settings = get_config($this->_modname);
$mform = $this->_form;
$lockedicon = html_writer::tag('span',
$OUTPUT->pix_icon('t/locked', get_string('locked', 'admin')),
array('class' => 'action-icon'));
$usermidnight = usergetmidnight(time());
foreach ($settings as $name => $value) {
if (strpos('_', $name) !== false) {
continue;
}
if ($mform->elementExists($name)) {
$element = $mform->getElement($name);
if ($element->getType() == 'date_time_selector') {
$enabledsetting = $name . '_enabled';
                    if (empty($settings->$enabledsetting)) {
$mform->setDefault($name, 0);
} else {
$relativetime = $usermidnight;
if (isset($datetimeoffsets[$name])) {
$relativetime = $datetimeoffsets[$name];
}
$mform->setDefault($name, $relativetime + $settings->$name);
}
} else {
$mform->setDefault($name, $settings->$name);
}
$advancedsetting = $name . '_adv';
if (!empty($settings->$advancedsetting)) {
$mform->setAdvanced($name);
}
$lockedsetting = $name . '_locked';
if (!empty($settings->$lockedsetting)) {
$mform->setConstant($name, $settings->$name);
$element->setLabel($element->getLabel() . $lockedicon);
// Do not use hardfreeze because we need the hidden input to check dependencies.
$element->freeze();
}
}
}
}
}
......@@ -479,6 +479,7 @@ $string['enablecomments'] = 'Enable comments';
$string['enablecourserequests'] = 'Enable course requests';
$string['enablecssoptimiser'] = 'Enable CSS optimiser';
$string['enablecssoptimiser_desc'] = 'When enabled CSS will be run through an optimisation process before being cached. The optimiser processes the CSS removing duplicate rules and styles, as well as white space removable and reformatting. Please note turning this on at the same time as theme designer mode is awful for performance but will help theme designers create optimised CSS.';
$string['enabled'] = 'Enabled';
$string['enabledevicedetection'] = 'Enable device detection';
$string['enablegravatar'] = 'Enable Gravatar';
$string['enablegravatar_help'] = 'When enabled Moodle will attempt to fetch a user profile picture from Gravatar if the user has not uploaded an image.';
......@@ -635,7 +636,7 @@ $string['localetext'] = 'Sitewide locale';
$string['localstringcustomization'] = 'Local string customization';
$string['location'] = 'Location';
$string['locationsettings'] = 'Location settings';
$string['locked'] = 'locked';
$string['locked'] = 'Locked';
$string['lockoutduration'] = 'Account lockout duration';
$string['lockoutduration_desc'] = 'Locked out account is automatically unlocked after this duration.';
$string['lockoutemailbody'] = 'Your account with username {$a->username} on server \'{$a->sitename}\'
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment