Skip to content

Commit

Permalink
MDL-67351 admin: Create new 'required' admin flag setting.
Browse files Browse the repository at this point in the history
Extend the admin flag options, that currently allow the 'advanced' and 'locked' states
of a form setting to be controlled by a plugins admin settings, to also include
the 'required' state. These options appear as a list of checkboxes next to the admin
setting.
  • Loading branch information
andrewmadden committed Jan 29, 2020
1 parent 4e41ace commit 948a951
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
6 changes: 5 additions & 1 deletion course/moodleform_mod.php
Expand Up @@ -1179,7 +1179,7 @@ protected function apply_admin_locked_flags() {
}

/**
* Get the list of admin settings for this module and apply any defaults/advanced/locked settings.
* Get the list of admin settings for this module and apply any defaults/advanced/locked/required 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
Expand Down Expand Up @@ -1221,6 +1221,10 @@ public function apply_admin_defaults($datetimeoffsets = array()) {
if (!empty($settings->$advancedsetting)) {
$mform->setAdvanced($name);
}
$requiredsetting = $name . '_required';
if (!empty($settings->$requiredsetting)) {
$mform->addRule($name, null, 'required', null, 'client');
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions lang/en/admin.php
Expand Up @@ -1039,6 +1039,7 @@
$string['requiredentrieschanged'] = 'Note: After upgrading, the setting \'Required entries before viewing\' is now enforced in the following database activities:<br/>{$a->text}<br/>';
$string['requiremodintro'] = 'Require activity description';
$string['requiremodintro_desc'] = 'If enabled, users will be forced to enter a description for each activity.';
$string['required'] = 'Required';
$string['requires'] = 'Requires';
$string['purgecaches'] = 'Purge all caches';
$string['purgecachesconfirm'] = 'Moodle can cache themes, javascript, language strings, filtered text, rss feeds and many other pieces of calculated data. Purging these caches will delete that data from the server and force browsers to refetch data, so that you can be sure you are seeing the most up-to-date values produced by the current code. There is no danger in purging caches, but your site may appear slower for a while until the server and clients calculate new information and cache it.';
Expand Down
12 changes: 11 additions & 1 deletion lib/adminlib.php
Expand Up @@ -1748,6 +1748,16 @@ public function set_locked_flag_options($enabled, $default) {
$this->set_flag_options($enabled, $default, 'locked', new lang_string('locked', 'core_admin'));
}

/**
* Set the required options flag on this admin setting.
*
* @param bool $enabled - One of self::OPTION_ENABLED or self::OPTION_DISABLED.
* @param bool $default - The default for the flag.
*/
public function set_required_flag_options($enabled, $default) {
$this->set_flag_options($enabled, $default, 'required', new lang_string('required', 'core_admin'));
}

/**
* Get the currently saved value for a setting flag
*
Expand Down Expand Up @@ -2074,7 +2084,7 @@ public function get_dependent_on() {

/**
* An additional option that can be applied to an admin setting.
* The currently supported options are 'ADVANCED' and 'LOCKED'.
* The currently supported options are 'ADVANCED', 'LOCKED' and 'REQUIRED'.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
Expand Down
6 changes: 6 additions & 0 deletions lib/upgrade.txt
Expand Up @@ -19,6 +19,12 @@ information provided here is intended especially for developers.
- $plugin->incompatible = 36;
incompatible takes a single int corresponding to the first incompatible branch. Any Moodle versions including and
above this will be prevented from installing the plugin, and a message will be given when attempting installation.
* Add 'required' admin flag for mod forms allows elements to be toggled between being required or not in admin settings.
- In mod settings, along with lock, advanced flags, the required flag can now be set with $setting->set_required_flag_options().
The name of the admin setting must be exactly the same as the mod_form element.
- Currently supported by:
- mod_assign
- mod_quiz

=== 3.8 ===
* Add CLI option to notify all cron tasks to stop: admin/cli/cron.php --stop
Expand Down

0 comments on commit 948a951

Please sign in to comment.