Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
qtype_gapselect_edit_form Class Reference

Select from drop down list question editing form definition. More...

Inheritance diagram for qtype_gapselect_edit_form:
qtype_gapselect_edit_form_base question_edit_form question_wizard_form moodleform

Public Member Functions

 _process_submission ($method)
 Internal method.
 
 _validate_files (&$files)
 Internal method.
 
 add_action_buttons ($cancel=true, $submitlabel=null)
 Use this method to a cancel and submit button to the end of your form.
 
 add_checkbox_controller ($groupid, $text=null, $attributes=null, $originalValue=0)
 Adds a link/button that controls the checked state of a group of checkboxes.
 
 add_sticky_action_buttons (bool $cancel=true, ?string $submitlabel=null)
 Use this method to make a sticky submit/cancel button at the end of your form.
 
 data_preprocessing ($question)
 Perform an preprocessing needed on the data passed to set_data() before it is used to initialise the form.
 
 definition_after_data ()
 Tweak the form with values provided by custom fields in use.
 
 display ()
 Print html form.
 
 filter_shown_headers (array $shownonly)
 Use this method to indicate that the fieldsets should be shown as expanded and all other fieldsets should be hidden.
 
 focus ($name=NULL)
 To autofocus on first form element or first element with error.
 
 get_data ()
 Return submitted data if properly submitted or returns NULL if validation fails or if there is no submitted data.
 
 get_file_content ($elname)
 Get content of uploaded file.
 
 get_maximum_choice_group_number ()
 Return how many different groups of choices there should be.
 
 get_new_filename ($elname=null)
 Returns name of uploaded file.
 
 get_submitted_data ()
 Return submitted data without validation or NULL if there is no submitted data.
 
 init_javascript_enhancement ($element, $enhancement, array $options=array(), array $strings=null)
 Adds an initialisation call for a standard JavaScript enhancement.
 
 is_cancelled ()
 Return true if a cancel button has been pressed resulting in the form being submitted.
 
 is_submitted ()
 Check that form was submitted.
 
 is_validated ()
 Check that form data is valid.
 
 moodleform ($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true)
 Old syntax of class constructor.
 
 no_submit_button_pressed ()
 Checks if button pressed is not for submitting the form.
 
 optional_param ($name, $default, $type)
 Checks if a parameter was passed in the previous form submission.
 
 qtype ()
 Override this in the subclass to question type name.
 
 render ()
 Renders the html form (same as display, but returns the result).
 
 repeat_elements ($elementobjs, $repeats, $options, $repeathiddenname, $addfieldsname, $addfieldsno=5, $addstring=null, $addbuttoninside=false, $deletebuttonname='')
 Method to add a repeating group of elements to a form.
 
 repeat_elements_fix_clone ($i, $elementclone, &$namecloned)
 Helper used by repeat_elements().
 
 save_file ($elname, $pathname, $override=false)
 Save file to standard filesystem.
 
 save_files ($destination)
 Save verified uploaded files into directory.
 
 save_stored_file ($elname, $newcontextid, $newcomponent, $newfilearea, $newitemid, $newfilepath='/', $newfilename=null, $overwrite=false, $newuserid=null)
 Save file to local filesystem pool.
 
 save_temp_file ($elname)
 Returns a temporary file, do not forget to delete after not needed any more.
 
 set_data ($question)
 Load in existing data as form defaults.
 
 set_display_vertical ()
 Set display mode for the form when labels take full width of the form and above the elements even on big screens.
 
 set_initial_dirty_state ($state=false)
 Set the initial 'dirty' state of the form.
 
 validate_defined_fields ($validateonnosubmit=false)
 Validate the form.
 
 validation ($data, $files)
 Dummy stub method - override if you needed to perform some extra validation.
 

Static Public Member Functions

static get_js_module ()
 Returns a JS module definition for the mforms JS.
 
static mock_ajax_submit ($simulatedsubmitteddata, $simulatedsubmittedfiles=array(), $method='post', $formidentifier=null)
 Used by tests to simulate submitted form data submission via AJAX.
 
static mock_generate_submit_keys ($data=[])
 Used by tests to generate valid submit keys for moodle forms that are submitted with ajax data.
 
static mock_submit ($simulatedsubmitteddata, $simulatedsubmittedfiles=array(), $method='post', $formidentifier=null)
 Used by tests to simulate submitted form data submission from the user.
 

Public Attributes

object $context
 current context
 
array $editoroptions
 html editor options
 
array $fileoptions
 options to preapre draft area
 
object $instance
 instance of question type
 
const DEFAULT_NUM_HINTS = 2
 

Protected Member Functions

 _get_post_params ()
 Internal method - should not be used anywhere.
 
 add_combined_feedback_fields ($withshownumpartscorrect=false)
 
 add_hidden_fields ()
 Add all the hidden form fields used by question/question.php.
 
 add_interactive_settings ($withclearwrong=false, $withshownumpartscorrect=false)
 
 add_per_answer_fields (&$mform, $label, $gradeoptions, $minoptions=QUESTION_NUMANS_START, $addoptions=QUESTION_NUMANS_ADD)
 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.
 
 add_tag_fields ($mform)
 Add the tag and course tag fields to the mform.
 
 after_definition ()
 After definition hook.
 
 can_preview ()
 Is the question being edited in a state where it can be previewed?
 
 choice_group ($mform)
 Creates an array with elements for a choice group.
 
 data_preprocessing_answers ($question, $withanswerfiles=false)
 Perform the necessary preprocessing for the fields added by add_per_answer_fields().
 
 data_preprocessing_choice ($question, $answer, $key)
 
 data_preprocessing_combined_feedback ($question, $withshownumcorrect=false)
 Perform the necessary preprocessing for the fields added by add_combined_feedback_fields().
 
 data_preprocessing_extra_answer_field ($answer, $field)
 Perfmorm preprocessing for particular extra answer field.
 
 data_preprocessing_extra_answer_fields ($question, $extraanswerfields)
 Perform the necessary preprocessing for the extra answer fields.
 
 data_preprocessing_hints ($question, $withclearwrong=false, $withshownumpartscorrect=false)
 Perform the necessary preprocessing for the hint fields.
 
 definition ()
 Build the form definition.
 
 definition_answer_choice (&$mform)
 Defines form elements for answer choices.
 
 definition_inner ($mform)
 definition_inner adds all specific fields to the form.
 
 extra_slot_validation (array $slots, array $choices)
 Finds more errors in question slots.
 
 get_array_value_by_keys (array $array, array $keys)
 Returns an element of multi-dimensional array given the list of keys.
 
 get_default_value (string $name, $default)
 Return default value for a given form element either from user_preferences table or $default.
 
 get_draft_files ($elname)
 Get draft files of a form element This is a protected method which will be used only inside moodleforms.
 
 get_form_identifier ()
 It should returns unique identifier for the form.
 
 get_hint_fields ($withclearwrong=false, $withshownumpartscorrect=false)
 Create the form elements required by one hint.
 
 get_illegal_tag_error ($text)
 Vaidate some input to make sure it does not contain any tags other than $this->allowedhtmltags.
 
 get_more_choices_string ()
 Language string to use for 'Add {no} more {whatever we call answers}'.
 
 get_non_collabsible_editor_options ()
 Returns an array of editor options with collapsed options turned off.
 
 get_per_answer_fields ($mform, $label, $gradeoptions, &$repeatedoptions, &$answersoption)
 Get the list of form elements to repeat, one for each answer.
 
 repeated_options ()
 Returns an array for form repeat options.
 
 validate_draft_files ()
 Internal method.
 

Protected Attributes

array $_ajaxformdata
 submitted form data when using mforms with ajax
 
mixed $_customdata
 globals workaround
 
object $_definition_finalized = false
 definition_after_data executed flag
 
MoodleQuickForm $_form
 quickform object definition
 
string $_formname
 name of the form
 
bool null $_validated = null
 stores the validation result of this form or null if not yet validated
 
array $allowedhtmltags = array()
 HTML tags allowed in answers (choices).
 
 $category
 
 $categorycontext
 
 $contexts
 
object $customfieldhandler
 instance of custom field
 
bool $customfieldpluginenabled = true
 custom field plugin enabled or disabled
 
object $question
 Question object with options and answers already loaded by get_question_options Be careful how you use this it is needed sometimes to set up the structure of the form in definition_inner but data is always loaded into the form with set_data.
 

Static Protected Attributes

static int $uniqueid = 0
 Unique identifier to be used for action buttons.
 

Detailed Description

Select from drop down list question editing form definition.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ add_per_answer_fields()

question_edit_form::add_per_answer_fields ( & $mform,
$label,
$gradeoptions,
$minoptions = QUESTION_NUMANS_START,
$addoptions = QUESTION_NUMANS_ADD )
protectedinherited

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.

Parameters
object$mformthe form being built.
$labelthe label to use for each option.
$gradeoptionsthe possible grades for each answer.
$minoptionsthe minimum number of answer blanks to display. Default QUESTION_NUMANS_START.
$addoptionsthe number of answer blanks to add. Default QUESTION_NUMANS_ADD.

◆ add_tag_fields()

question_edit_form::add_tag_fields ( $mform)
protectedinherited

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.

Parameters
object$mformThe form being built

◆ can_preview()

question_edit_form::can_preview ( )
protectedinherited

Is the question being edited in a state where it can be previewed?

Return values
boolwhether to show the preview link.

Reimplemented in qtype_calculated_edit_form, qtype_calculatedmulti_edit_form, and qtype_calculatedsimple_edit_form.

◆ choice_group()

qtype_gapselect_edit_form_base::choice_group ( $mform)
protectedinherited

Creates an array with elements for a choice group.

Parameters
object$mformThe Moodle form we are working with
int$maxgroupThe number of max group generate element select.
Return values
arrayArray for form elements

Reimplemented in qtype_ddwtos_edit_form.

◆ data_preprocessing()

qtype_gapselect_edit_form_base::data_preprocessing ( $question)
inherited

Perform an preprocessing needed on the data passed to set_data() before it is used to initialise the form.

Parameters
object$questionthe data being passed to the form.
Return values
object\$questionthe modified data.

Reimplemented from question_edit_form.

◆ data_preprocessing_answers()

question_edit_form::data_preprocessing_answers ( $question,
$withanswerfiles = false )
protectedinherited

Perform the necessary preprocessing for the fields added by add_per_answer_fields().

Parameters
object$questionthe data being passed to the form.
Return values
object\$questionthe modified data.

Reimplemented in qtype_calculated_edit_form, qtype_calculatedmulti_edit_form, and qtype_numerical_edit_form.

◆ data_preprocessing_combined_feedback()

question_edit_form::data_preprocessing_combined_feedback ( $question,
$withshownumcorrect = false )
protectedinherited

Perform the necessary preprocessing for the fields added by add_combined_feedback_fields().

Parameters
object$questionthe data being passed to the form.
Return values
object\$questionthe modified data.

◆ data_preprocessing_extra_answer_field()

question_edit_form::data_preprocessing_extra_answer_field ( $answer,
$field )
protectedinherited

Perfmorm preprocessing for particular extra answer field.

Questions with non-trivial DB - form element relationship will want to override this.

Parameters
object$answeran answer object to get extra field from.
string$fieldextra answer field name.
Return values
fieldvalue to be set to the form.

◆ data_preprocessing_extra_answer_fields()

question_edit_form::data_preprocessing_extra_answer_fields ( $question,
$extraanswerfields )
protectedinherited

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.

Parameters
object$questionthe data being passed to the form.
array$extraanswerfieldsextra answer fields (without table name).
Return values
object\$questionthe modified data.

◆ data_preprocessing_hints()

question_edit_form::data_preprocessing_hints ( $question,
$withclearwrong = false,
$withshownumpartscorrect = false )
protectedinherited

Perform the necessary preprocessing for the hint fields.

Parameters
object$questionThe data being passed to the form.
bool$withclearwrongClear wrong hints.
bool$withshownumpartscorrectShow number correct.
Return values
stdClassThe modified data.

Reimplemented in qtype_ddmarker_edit_form, and qtype_ordering_edit_form.

◆ definition()

question_edit_form::definition ( )
protectedinherited

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().

Reimplemented from moodleform.

Reimplemented in qtype_random_edit_form.

◆ definition_after_data()

question_edit_form::definition_after_data ( )
inherited

Tweak the form with values provided by custom fields in use.

Reimplemented from moodleform.

◆ definition_answer_choice()

qtype_gapselect_edit_form_base::definition_answer_choice ( & $mform)
protectedinherited

Defines form elements for answer choices.

Parameters
object$mformThe Moodle form object being built

◆ definition_inner()

qtype_gapselect_edit_form_base::definition_inner ( $mform)
protectedinherited

definition_inner adds all specific fields to the form.

Parameters
object$mform(the form being built).

Reimplemented from question_edit_form.

◆ extra_slot_validation()

qtype_gapselect_edit_form_base::extra_slot_validation ( array $slots,
array $choices )
protectedinherited

Finds more errors in question slots.

Parameters
array$slotsThe question text
array$choicesQuestion choices
Return values
string|nullError message or false if no errors

Reimplemented in qtype_ddwtos_edit_form.

◆ get_default_value()

question_edit_form::get_default_value ( string $name,
$default )
protectedinherited

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}));

Parameters
string$namethe name of the form field.
mixed$defaultdefault value.
Return values
string|nulldefault value for a given form element.

◆ get_hint_fields()

question_edit_form::get_hint_fields ( $withclearwrong = false,
$withshownumpartscorrect = false )
protectedinherited

Create the form elements required by one hint.

Parameters
string$withclearwrongwhether this quesiton type uses the 'Clear wrong' option on hints.
string$withshownumpartscorrectwhether this quesiton type uses the 'Show num parts correct' option on hints.
Return values
arrayform field elements for one hint.

Reimplemented in qtype_ddmarker_edit_form, qtype_multichoice_edit_form, and qtype_ordering_edit_form.

◆ get_illegal_tag_error()

qtype_gapselect_edit_form_base::get_illegal_tag_error ( $text)
protectedinherited

Vaidate some input to make sure it does not contain any tags other than $this->allowedhtmltags.

Parameters
string$textthe input to validate.
Return values
stringany validation errors.

◆ get_maximum_choice_group_number()

qtype_gapselect_edit_form::get_maximum_choice_group_number ( )

Return how many different groups of choices there should be.

Return values
intthe maximum group number.

Reimplemented from qtype_gapselect_edit_form_base.

◆ get_more_choices_string()

question_edit_form::get_more_choices_string ( )
protectedinherited

Language string to use for 'Add {no} more {whatever we call answers}'.

Reimplemented in qtype_match_edit_form, qtype_numerical_edit_form, and qtype_shortanswer_edit_form.

◆ get_non_collabsible_editor_options()

question_edit_form::get_non_collabsible_editor_options ( )
protectedinherited

Returns an array of editor options with collapsed options turned off.

Deprecated
since 2.6
Return values
array

◆ get_per_answer_fields()

question_edit_form::get_per_answer_fields ( $mform,
$label,
$gradeoptions,
& $repeatedoptions,
& $answersoption )
protectedinherited

Get the list of form elements to repeat, one for each answer.

Parameters
object$mformthe form being built.
$labelthe label to use for each option.
$gradeoptionsthe possible grades for each answer.
$repeatedoptionsreference to array of repeated options to fill
$answersoptionreference to return the name of $question->options field holding an array of answers
Return values
arrayof form fields.

Reimplemented in qtype_calculated_edit_form, qtype_calculatedmulti_edit_form, qtype_match_edit_form, qtype_multichoice_edit_form, and qtype_numerical_edit_form.

◆ qtype()

qtype_gapselect_edit_form::qtype ( )

Override this in the subclass to question type name.

Return values
thequestion type name, should be the same as the name() method in the question type class.

Reimplemented from qtype_gapselect_edit_form_base.

◆ repeated_options()

qtype_gapselect_edit_form_base::repeated_options ( )
protectedinherited

Returns an array for form repeat options.

Return values
arrayArray of repeate options

◆ set_data()

question_edit_form::set_data ( $default_values)
inherited

Load in existing data as form defaults.

Usually new entry defaults are stored directly in form definition (new entry form); this function is used to load in data where values already exist and data is being edited (edit entry form).

note: $slashed param removed

Parameters
stdClass | array$default_valuesobject or array of default values

Reimplemented from moodleform.

Reimplemented in qtype_missingtype_edit_form, qtype_multianswer_edit_form, and qtype_random_edit_form.

◆ validation()

qtype_gapselect_edit_form_base::validation ( $data,
$files )
inherited

Dummy stub method - override if you needed to perform some extra validation.

If there are errors return array of errors ("fieldname"=>"error message"), otherwise true if ok.

Server side rules do not work for uploaded files, implement serverside rules here if needed.

Parameters
array$dataarray of ("fieldname"=>value) of submitted data
array$filesarray of uploaded files "element_name"=>tmp_file_path
Return values
arrayof "element_name"=>"error_description" if there are errors, or an empty array if everything is OK (true allowed for backwards compatibility too).

Reimplemented from question_edit_form.


The documentation for this class was generated from the following file: