Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402] [Versions 402 and 403]

A base class for question editing forms.

Copyright: 2006 The Open University
License: http://www.gnu.org/copyleft/gpl.html GNU Public License
File Size: 922 lines (41 kb)
Included or required:0 times
Referenced: 5 times
Includes or requires: 0 files

Defines 2 classes


Class: question_wizard_form  - X-Ref

add_hidden_fields()   X-Ref
Add all the hidden form fields used by question/question.php.


Class: question_edit_form  - X-Ref

Form definition base class. This defines the common fields that
all question types need. Question types should define their own
class that inherits from this one, and implements the definition_inner()
method.

__construct($submiturl, $question, $category, $contexts, $formeditable = true)   X-Ref
No description

get_default_value(string $name, $default)   X-Ref
Return default value for a given form element either from user_preferences table or $default.

To make use of user_preferences in your qtype default settings, you need to replace
$mform->setDefault({elementname}, {defaultvalue}); in edit_{qtypename}_form.php with
$mform->setDefault({elementname}, $this->get_default_value({elementname}, {defaultvalue}));

param: string $name the name of the form field.
param: mixed $default default value.
return: string|null default value for a given form element.

definition()   X-Ref
Build the form definition.

This adds all the form fields that the default question type supports.
If your question type does not support all these fields, then you can
override this method and remove the ones you don't want with $mform->removeElement().

definition_inner($mform)   X-Ref
Add any question-type specific form fields.

param: object $mform the form being built.

definition_after_data()   X-Ref
Tweak the form with values provided by custom fields in use.


can_preview()   X-Ref
Is the question being edited in a state where it can be previewed?

return: bool whether to show the preview link.

get_per_answer_fields($mform, $label, $gradeoptions,&$repeatedoptions, &$answersoption)   X-Ref
Get the list of form elements to repeat, one for each answer.

param: object $mform the form being built.
param: $label the label to use for each option.
param: $gradeoptions the possible grades for each answer.
param: $repeatedoptions reference to array of repeated options to fill
param: $answersoption reference to return the name of $question->options
return: array of form fields.

add_tag_fields($mform)   X-Ref
Add the tag and course tag fields to the mform.

If the form is being built in a course context then add the field
for course tags.

If the question category doesn't belong to a course context or we
aren't editing in a course context then add the tags element to allow
tags to be added to the question category context.

param: object $mform The form being built

add_per_answer_fields(&$mform, $label, $gradeoptions,$minoptions = QUESTION_NUMANS_START, $addoptions = QUESTION_NUMANS_ADD)   X-Ref
Add a set of form fields, obtained from get_per_answer_fields, to the form,
one for each existing answer, with some blanks for some new ones.

param: object $mform the form being built.
param: $label the label to use for each option.
param: $gradeoptions the possible grades for each answer.
param: $minoptions the minimum number of answer blanks to display.
param: $addoptions the number of answer blanks to add. Default QUESTION_NUMANS_ADD.

get_more_choices_string()   X-Ref
Language string to use for 'Add {no} more {whatever we call answers}'.


add_combined_feedback_fields($withshownumpartscorrect = false)   X-Ref
No description

get_hint_fields($withclearwrong = false, $withshownumpartscorrect = false)   X-Ref
Create the form elements required by one hint.

param: string $withclearwrong whether this quesiton type uses the 'Clear wrong' option on hints.
param: string $withshownumpartscorrect whether this quesiton type uses the 'Show num parts correct' option on hints.
return: array form field elements for one hint.

add_interactive_settings($withclearwrong = false,$withshownumpartscorrect = false)   X-Ref
No description

set_data($question)   X-Ref
No description

data_preprocessing($question)   X-Ref
Perform an preprocessing needed on the data passed to {@link set_data()}
before it is used to initialise the form.

param: object $question the data being passed to the form.
return: object $question the modified data.

data_preprocessing_answers($question, $withanswerfiles = false)   X-Ref
Perform the necessary preprocessing for the fields added by
{@link add_per_answer_fields()}.

param: object $question the data being passed to the form.
return: object $question the modified data.

data_preprocessing_extra_answer_fields($question, $extraanswerfields)   X-Ref
Perform the necessary preprocessing for the extra answer fields.

Questions that do something not trivial when editing extra answer fields
will want to override this.
param: object $question the data being passed to the form.
param: array $extraanswerfields extra answer fields (without table name).
return: object $question the modified data.

data_preprocessing_extra_answer_field($answer, $field)   X-Ref
Perfmorm preprocessing for particular extra answer field.

Questions with non-trivial DB - form element relationship will
want to override this.
param: object $answer an answer object to get extra field from.
param: string $field extra answer field name.
return: field value to be set to the form.

data_preprocessing_combined_feedback($question,$withshownumcorrect = false)   X-Ref
Perform the necessary preprocessing for the fields added by
{@link add_combined_feedback_fields()}.

param: object $question the data being passed to the form.
return: object $question the modified data.

data_preprocessing_hints($question, $withclearwrong = false,$withshownumpartscorrect = false)   X-Ref
Perform the necessary preprocessing for the hint fields.

param: object $question the data being passed to the form.
return: object $question the modified data.

validation($fromform, $files)   X-Ref
No description

get_non_collabsible_editor_options()   X-Ref
Returns an array of editor options with collapsed options turned off.

return: array