Skip to content

Commit

Permalink
MDL-81075 quiz: config option for defaults when creating questions
Browse files Browse the repository at this point in the history
  • Loading branch information
glepod authored and cameron1729 committed Jul 16, 2024
1 parent fd487cd commit 2afdd8d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
12 changes: 12 additions & 0 deletions admin/settings/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,18 @@
$settings->add(new admin_setting_configselect('question_preview/history',
get_string('responsehistory', 'question'), '', 0, $hiddenofvisible));

// Question editing settings.
$settings = new admin_settingpage('qediting',
get_string('questionediting', 'question'),
'moodle/question:config');
$ADMIN->add('qtypesettings', $settings);

$settings->add(new admin_setting_heading('qediting_options',
'', get_string('questionediting_desc', 'question')));

$settings->add(new admin_setting_configcheckbox('questiondefaultssave',
get_string('questiondefaultssave', 'question'), get_string('questiondefaultssave_desc', 'question'), 1));

// Settings for particular question types.
$plugins = core_plugin_manager::instance()->get_plugins_of_type('qtype');
core_collator::asort_objects_by_property($plugins, 'displayname');
Expand Down
4 changes: 4 additions & 0 deletions lang/en/question.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,10 @@
$string['questionbehavioursdisabledexplained'] = 'Enter a comma-separated list of behaviours you do not want to appear in the drop-down menu.';
$string['questionbehavioursorder'] = 'Question behaviours order';
$string['questionbehavioursorderexplained'] = 'Enter a comma-separated list of behaviours in the order you want them to appear in the drop-down menu.';
$string['questiondefaultssave'] = 'Enable saving question defaults';
$string['questiondefaultssave_desc'] = 'When enabled, the value of certain question form elements will be saved as user preferences when the question editing form is submitted. The value stored in the user preference will then be used as the default value the next time the form is viewed.';
$string['questionediting'] = 'Question editing';
$string['questionediting_desc'] = 'These settings control aspects of the question editing forms';
$string['questionidmismatch'] = 'Question ids mismatch';
$string['questionformtagheader'] = '{$a} tags';
$string['questionname'] = 'Question name';
Expand Down
4 changes: 2 additions & 2 deletions question/bank/editquestion/question.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@
}
}

// If this is a new question, save defaults for user in user_preferences table.
if (empty($question->id)) {
// If this is a new question and question defaults save is enabled, save defaults for user in user_preferences table.
if (empty($question->id) && !empty($CFG->questiondefaultssave)) {
$qtypeobj->save_defaults_for_new_questions($fromform);
}
$question = $qtypeobj->save_question($question, $fromform);
Expand Down
7 changes: 6 additions & 1 deletion question/type/edit_question_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ public function __construct($submiturl, $question, $category, $contexts, $formed
* @return string|null default value for a given form element.
*/
protected function get_default_value(string $name, $default): ?string {
return question_bank::get_qtype($this->qtype())->get_default_value($name, $default);
global $CFG;

if (!empty($CFG->questiondefaultssave)) {
return question_bank::get_qtype($this->qtype())->get_default_value($name, $default);
}
return $default;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

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

$version = 2024071200.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2024071600.00; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.5dev (Build: 20240712)'; // Human-friendly version name
Expand Down

0 comments on commit 2afdd8d

Please sign in to comment.