MDL-71262 Questions: Default options for qtype_essay
This commit is contained in:
@@ -43,16 +43,17 @@ class qtype_essay_edit_form extends question_edit_form {
|
||||
|
||||
$mform->addElement('select', 'responseformat',
|
||||
get_string('responseformat', 'qtype_essay'), $qtype->response_formats());
|
||||
$mform->setDefault('responseformat', 'editor');
|
||||
$mform->setDefault('responseformat', $this->get_default_value('responseformat', 'editor'));
|
||||
|
||||
|
||||
$mform->addElement('select', 'responserequired',
|
||||
get_string('responserequired', 'qtype_essay'), $qtype->response_required_options());
|
||||
$mform->setDefault('responserequired', 1);
|
||||
$mform->setDefault('responserequired', $this->get_default_value('responserequired', 1));
|
||||
$mform->hideIf('responserequired', 'responseformat', 'eq', 'noinline');
|
||||
|
||||
$mform->addElement('select', 'responsefieldlines',
|
||||
get_string('responsefieldlines', 'qtype_essay'), $qtype->response_sizes());
|
||||
$mform->setDefault('responsefieldlines', 10);
|
||||
$mform->setDefault('responsefieldlines', $this->get_default_value('responsefieldlines', 10));
|
||||
$mform->hideIf('responsefieldlines', 'responseformat', 'eq', 'noinline');
|
||||
|
||||
// Create a text box that can be enabled/disabled for max/min word limits options.
|
||||
@@ -79,11 +80,11 @@ class qtype_essay_edit_form extends question_edit_form {
|
||||
|
||||
$mform->addElement('select', 'attachments',
|
||||
get_string('allowattachments', 'qtype_essay'), $qtype->attachment_options());
|
||||
$mform->setDefault('attachments', 0);
|
||||
$mform->setDefault('attachments', $this->get_default_value('attachments', 0));
|
||||
|
||||
$mform->addElement('select', 'attachmentsrequired',
|
||||
get_string('attachmentsrequired', 'qtype_essay'), $qtype->attachments_required_options());
|
||||
$mform->setDefault('attachmentsrequired', 0);
|
||||
$mform->setDefault('attachmentsrequired', $this->get_default_value('attachmentsrequired', 0));
|
||||
$mform->addHelpButton('attachmentsrequired', 'attachmentsrequired', 'qtype_essay');
|
||||
$mform->hideIf('attachmentsrequired', 'attachments', 'eq', 0);
|
||||
|
||||
@@ -92,7 +93,7 @@ class qtype_essay_edit_form extends question_edit_form {
|
||||
$mform->hideIf('filetypeslist', 'attachments', 'eq', 0);
|
||||
|
||||
$mform->addElement('select', 'maxbytes', get_string('maxbytes', 'qtype_essay'), $qtype->max_file_size_options());
|
||||
$mform->setDefault('maxbytes', '0');
|
||||
$mform->setDefault('maxbytes', $this->get_default_value('maxbytes', 0));
|
||||
$mform->hideIf('maxbytes', 'attachments', 'eq', 0);
|
||||
|
||||
$mform->addElement('header', 'responsetemplateheader', get_string('responsetemplateheader', 'qtype_essay'));
|
||||
|
||||
@@ -51,6 +51,16 @@ class qtype_essay extends question_type {
|
||||
parent::get_question_options($question);
|
||||
}
|
||||
|
||||
public function save_defaults_for_new_questions(stdClass $fromform): void {
|
||||
parent::save_defaults_for_new_questions($fromform);
|
||||
$this->set_default_value('responseformat', $fromform->responseformat);
|
||||
$this->set_default_value('responserequired', $fromform->responserequired);
|
||||
$this->set_default_value('responsefieldlines', $fromform->responsefieldlines);
|
||||
$this->set_default_value('attachments', $fromform->attachments);
|
||||
$this->set_default_value('attachmentsrequired', $fromform->attachmentsrequired);
|
||||
$this->set_default_value('maxbytes', $fromform->maxbytes);
|
||||
}
|
||||
|
||||
public function save_question_options($formdata) {
|
||||
global $DB;
|
||||
$context = $formdata->context;
|
||||
|
||||
@@ -31,5 +31,30 @@ Feature: Test creating an Essay question
|
||||
| Question name | essay-002 |
|
||||
| Question text | Write an essay with 500 words. |
|
||||
| General feedback | This is general feedback |
|
||||
| Response format | HTML editor |
|
||||
| id_responseformat | editorfilepicker |
|
||||
Then I should see "essay-002"
|
||||
|
||||
@javascript
|
||||
Scenario: Create an Essay question for testing some default options
|
||||
When I add a "Essay" question filling the form with:
|
||||
| Question name | essay-003 |
|
||||
| Question text | Write an essay with 500 words. |
|
||||
| General feedback | This is general feedback |
|
||||
| id_responseformat | editorfilepicker |
|
||||
| id_responserequired | 0 |
|
||||
| id_responsefieldlines | 15 |
|
||||
| id_attachments | 2 |
|
||||
| id_attachmentsrequired | 2 |
|
||||
| id_maxbytes | 10240 |
|
||||
Then I should see "essay-003"
|
||||
# Checking that the next new question form displays user preferences settings.
|
||||
When I press "Create a new question ..."
|
||||
And I set the field "item_qtype_essay" to "1"
|
||||
And I click on "Add" "button" in the "Choose a question type to add" "dialogue"
|
||||
Then the following fields match these values:
|
||||
| id_responseformat | editorfilepicker |
|
||||
| id_responserequired | 0 |
|
||||
| id_responsefieldlines | 15 |
|
||||
| id_attachments | 2 |
|
||||
| id_attachmentsrequired | 2 |
|
||||
| id_maxbytes | 10240 |
|
||||
|
||||
Reference in New Issue
Block a user