Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
|
IMS CP configuration form. More...
Public Member Functions | |
_process_submission ($method) | |
Internal method. More... | |
_validate_files (&$files) | |
Internal method. More... | |
add_action_buttons ($cancel=true, $submitlabel=null) | |
Use this method to a cancel and submit button to the end of your form. More... | |
add_action_buttons ($cancel=true, $submitlabel=null, $submit2label=null) | |
Overriding formslib's add_action_buttons() method, to add an extra submit "save changes and return" button. More... | |
add_checkbox_controller ($groupid, $text=null, $attributes=null, $originalValue=0) | |
Adds a link/button that controls the checked state of a group of checkboxes. More... | |
add_completion_rules () | |
Can be overridden to add custom completion rules if the module wishes them. More... | |
apply_admin_defaults ($datetimeoffsets=array()) | |
Get the list of admin settings for this module and apply any defaults/advanced/locked/required settings. More... | |
completion_rule_enabled ($data) | |
Called during validation. More... | |
data_postprocessing ($data) | |
Allows modules to modify the data returned by form get_data(). More... | |
data_preprocessing (&$default_values) | |
Allows module to modify data returned by get_moduleinfo_data() or prepare_new_moduleinfo_data() before calling set_data() This method is also called in the bulk activity completion form. More... | |
definition () | |
Define the form - called by parent constructor. More... | |
definition_after_data () | |
Each module which defines definition_after_data() must call this method using parent::definition_after_data();. More... | |
display () | |
Print html form. More... | |
focus ($name=NULL) | |
To autofocus on first form element or first element with error. More... | |
get_context () | |
Return the course context for new modules, or the module context for existing modules. More... | |
get_course () | |
Get the course id. More... | |
get_coursemodule () | |
Get the course module object. More... | |
get_current () | |
Get the current data for the form. More... | |
get_data () | |
Return submitted data if properly submitted or returns NULL if validation fails or if there is no submitted data. More... | |
get_features () | |
Return the features this module supports. More... | |
get_file_content ($elname) | |
Get content of uploaded file. More... | |
get_instance () | |
Get the DB record for the current instance. More... | |
get_new_filename ($elname=null) | |
Returns name of uploaded file. More... | |
get_section () | |
Get the course section number (relative). More... | |
get_submitted_data () | |
Return submitted data without validation or NULL if there is no submitted data. More... | |
init_javascript_enhancement ($element, $enhancement, array $options=array(), array $strings=null) | |
Adds an initialisation call for a standard JavaScript enhancement. More... | |
is_cancelled () | |
Return true if a cancel button has been pressed resulting in the form being submitted. More... | |
is_submitted () | |
Check that form was submitted. More... | |
is_validated () | |
Check that form data is valid. More... | |
moodleform ($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true) | |
Old syntax of class constructor. More... | |
moodleform_mod ($current, $section, $cm, $course) | |
Old syntax of class constructor. More... | |
no_submit_button_pressed () | |
Checks if button pressed is not for submitting the form. More... | |
optional_param ($name, $default, $type) | |
Checks if a parameter was passed in the previous form submission. More... | |
render () | |
Renders the html form (same as display, but returns the result). More... | |
repeat_elements ($elementobjs, $repeats, $options, $repeathiddenname, $addfieldsname, $addfieldsno=5, $addstring=null, $addbuttoninside=false) | |
Method to add a repeating group of elements to a form. More... | |
repeat_elements_fix_clone ($i, $elementclone, &$namecloned) | |
Helper used by repeat_elements(). More... | |
save_file ($elname, $pathname, $override=false) | |
Save file to standard filesystem. More... | |
save_files ($destination) | |
Save verified uploaded files into directory. More... | |
save_stored_file ($elname, $newcontextid, $newcomponent, $newfilearea, $newitemid, $newfilepath='/', $newfilename=null, $overwrite=false, $newuserid=null) | |
Save file to local filesystem pool. More... | |
save_temp_file ($elname) | |
Returns a temporary file, do not forget to delete after not needed any more. More... | |
set_data ($default_values) | |
Load in existing data as form defaults. More... | |
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. More... | |
set_initial_dirty_state ($state=false) | |
Set the initial 'dirty' state of the form. More... | |
standard_grading_coursemodule_elements () | |
standard_hidden_coursemodule_elements () | |
validate_defined_fields ($validateonnosubmit=false) | |
Validate the form. More... | |
validation ($data, $files) | |
Perform minimal validation on the settings form. More... | |
Static Public Member Functions | |
static | get_js_module () |
Returns a JS module definition for the mforms JS. More... | |
static | mock_generate_submit_keys ($data=[]) |
Used by tests to generate valid submit keys for moodle forms that are submitted with ajax data. More... | |
static | mock_submit ($simulatedsubmitteddata, $simulatedsubmittedfiles=array(), $method='post', $formidentifier=null) |
Used by tests to simulate submitted form data submission from the user. More... | |
Protected Member Functions | |
_get_post_params () | |
Internal method - should not be used anywhere. More... | |
add_intro_editor ($required=null, $customlabel=null) | |
Add an editor for an activity's introduction field. More... | |
add_rating_settings ($mform, int $itemnumber) | |
Add rating settings. More... | |
after_definition () | |
After definition hook. More... | |
apply_admin_locked_flags () | |
Get the list of admin settings for this module and apply any locked settings. More... | |
get_draft_files ($elname) | |
Get draft files of a form element This is a protected method which will be used only inside moodleforms. More... | |
get_form_identifier () | |
It should returns unique identifier for the form. More... | |
init_features () | |
plugin_extend_coursemodule_standard_elements () | |
Plugins can extend the coursemodule settings form. | |
plugin_extend_coursemodule_validation ($data) | |
Extend the validation function from any other plugin. More... | |
standard_coursemodule_elements () | |
Adds all the standard elements to a form to edit the settings for an activity module. | |
standard_intro_elements ($customlabel=null) | |
Add an editor for an activity's introduction field. More... | |
validate_draft_files () | |
Internal method. More... | |
Protected Attributes | |
array | $_ajaxformdata |
submitted form data when using mforms with ajax | |
mixed | $_cm |
Course module record of the module that is being updated. More... | |
mixed | $_course |
Current course. | |
array | $_customcompletionelements |
Custom completion-rule elements, if enabled. | |
array | $_customdata |
globals workaround | |
object | $_definition_finalized = false |
definition_after_data executed flag | |
$_features | |
List of modform features. | |
MoodleQuickForm | $_form |
quickform object definition | |
string | $_formname |
name of the form | |
mixed | $_instance |
Instance of the module that is being updated. More... | |
string | $_modname |
name of module. | |
$_outcomesused | |
a flag indicating whether outcomes are being used | |
int | $_section |
Section of course that module instance will be put in or is in. More... | |
bool null | $_validated = null |
stores the validation result of this form or null if not yet validated | |
bool | $applyadminlockedflags = false |
A flag used to indicate that this module should lock settings based on admin settings flags in definition_after_data. | |
$context | |
current context, course or module depends if already exists | |
object | $courseformat |
The course format of the current course. | |
$current | |
Current data. | |
IMS CP configuration form.
|
protectedinherited |
|
inherited |
Internal method.
Alters submitted data to be suitable for quickforms processing. Must be called when the form is fully set up.
string | $method | name of the method which alters submitted data |
|
inherited |
Internal method.
Validates all old-style deprecated uploaded files. The new way is to upload files via repository api.
array | $files | list of files to be validated |
bool|array | Success or an array of errors |
|
inherited |
Use this method to a cancel and submit button to the end of your form.
Pass a param of false if you don't want a cancel button in your form. If you have a cancel button make sure you check for it being pressed using is_cancelled() and redirecting if it is true before trying to get data with get_data().
bool | $cancel | whether to show cancel button, default true |
string | $submitlabel | label for submit button, defaults to get_string('savechanges') |
Reimplemented in tool_uploadcourse_step2_form, and core_contentbank\form\edit_content.
|
inherited |
Overriding formslib's add_action_buttons() method, to add an extra submit "save changes and return" button.
bool | $cancel | show cancel button |
string | $submitlabel | null means default, false means none, string is label text |
string | $submit2label | null means default, false means none, string is label text |
void |
|
inherited |
Adds a link/button that controls the checked state of a group of checkboxes.
int | $groupid | The id of the group of advcheckboxes this element controls |
string | $text | The text of the link. Defaults to selectallornone ("select all/none") |
array | $attributes | associative array of HTML attributes |
int | $originalValue | The original general state of the checkboxes before the user first clicks this element |
|
inherited |
Can be overridden to add custom completion rules if the module wishes them.
If overriding this, you should also override completion_rule_enabled.
Just add elements to the form as needed and return the list of IDs. The system will call disabledIf and handle other behaviour for each returned ID.
array | Array of string IDs of added items, empty array if none |
Reimplemented in mod_assign_mod_form, mod_choice_mod_form, mod_data_mod_form, mod_feedback_mod_form, mod_forum_mod_form, mod_glossary_mod_form, mod_lesson_mod_form, mod_quiz_mod_form, mod_scorm_mod_form, and mod_survey_mod_form.
|
protectedinherited |
Add an editor for an activity's introduction field.
null | $required | Override system default for requiremodintro |
null | $customlabel | Override default label for editor |
coding_exception |
|
protectedinherited |
Add rating settings.
moodleform_mod | $mform | |
int | $itemnumber |
|
protectedinherited |
After definition hook.
This is useful for intermediate classes to inject logic after the definition was provided without requiring developers to call the parent self::definition()
} as it's not obvious by design. The 'intermediate' class is 'MyClass extends IntermediateClass extends moodleform'.
Classes overriding this method should always call the parent. We may not add anything specifically in this instance of the method, but intermediate classes are likely to do so, and so it is a good practice to always call the parent.
void |
Reimplemented in core\form\persistent.
|
inherited |
Get the list of admin settings for this module and apply any defaults/advanced/locked/required settings.
$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 date/time fields are set relative to the users current midnight. |
void |
|
protectedinherited |
Get the list of admin settings for this module and apply any locked settings.
This cannot happen in apply_admin_defaults because we do not the current values of the settings in that function because set_data has not been called yet.
void |
|
inherited |
Called during validation.
Override to indicate, based on the data, whether a custom completion rule is enabled (selected).
array | $data | Input data (not yet validated) |
bool | True if one or more rules is enabled, false if none are; default returns false |
Reimplemented in mod_assign_mod_form, mod_choice_mod_form, mod_data_mod_form, mod_feedback_mod_form, mod_forum_mod_form, mod_glossary_mod_form, mod_lesson_mod_form, mod_quiz_mod_form, mod_scorm_mod_form, and mod_survey_mod_form.
|
inherited |
Allows modules to modify the data returned by form get_data().
This method is also called in the bulk activity completion form.
Only available on moodleform_mod.
stdClass | $data | passed by reference |
Reimplemented in mod_choice_mod_form, mod_data_mod_form, mod_feedback_mod_form, mod_forum_mod_form, mod_glossary_mod_form, mod_h5pactivity_mod_form, mod_lesson_mod_form, mod_scorm_mod_form, mod_survey_mod_form, and mod_workshop_mod_form.
|
inherited |
Allows module to modify data returned by get_moduleinfo_data() or prepare_new_moduleinfo_data() before calling set_data() This method is also called in the bulk activity completion form.
Only available on moodleform_mod.
array | $default_values | passed by reference |
Reimplemented in mod_workshop_mod_form, mod_choice_mod_form, mod_feedback_mod_form, mod_folder_mod_form, mod_forum_mod_form, mod_glossary_mod_form, mod_resource_mod_form, mod_url_mod_form, mod_assign_mod_form, mod_data_mod_form, mod_h5pactivity_mod_form, mod_lesson_mod_form, mod_page_mod_form, mod_scorm_mod_form, and mod_quiz_mod_form.
mod_imscp_mod_form::definition | ( | ) |
Define the form - called by parent constructor.
Reimplemented from moodleform.
|
inherited |
Each module which defines definition_after_data() must call this method using parent::definition_after_data();.
Reimplemented from moodleform.
Reimplemented in mod_forum_mod_form, mod_glossary_mod_form, mod_resource_mod_form, and mod_workshop_mod_form.
|
inherited |
Print html form.
Reimplemented in base_moodleform, cohort_upload_form, and mod_feedback_complete_form.
|
inherited |
To autofocus on first form element or first element with error.
string | $name | if this is set then the focus is forced to a field with this name |
string | javascript to select form element with first error or first element if no errors. Use this as a parameter when calling print_header |
|
inherited |
Return the course context for new modules, or the module context for existing modules.
context |
|
inherited |
Get the course id.
int |
|
inherited |
Get the course module object.
stdClass|null |
|
inherited |
Get the current data for the form.
stdClass|null |
|
inherited |
Return submitted data if properly submitted or returns NULL if validation fails or if there is no submitted data.
Do not override this method, override data_postprocessing() instead.
object | submitted data; NULL if not valid or not submitted or cancelled |
Reimplemented from moodleform.
Reimplemented in mod_forum_mod_form.
|
protectedinherited |
Get draft files of a form element This is a protected method which will be used only inside moodleforms.
string | $elname | name of element |
array|bool|null |
|
inherited |
Return the features this module supports.
stdClass |
|
inherited |
Get content of uploaded file.
string | $elname | name of file upload element |
string|bool | false in case of failure, string if ok |
|
protectedinherited |
It should returns unique identifier for the form.
Currently it will return class name, but in case two same forms have to be rendered on same page then override function to get unique form identifier. e.g This is used on multiple self enrollments page.
string | form identifier. |
Reimplemented in enrol_self_enrol_form, and mod_assign_grade_form.
|
inherited |
Get the DB record for the current instance.
stdClass|null |
|
staticinherited |
Returns a JS module definition for the mforms JS.
array |
|
inherited |
Returns name of uploaded file.
string | $elname | first element if null |
string|bool | false in case of failure, string if ok |
|
inherited |
Get the course section number (relative).
int |
|
inherited |
Return submitted data without validation or NULL if there is no submitted data.
note: $slashed param removed
object | submitted data; NULL if not submitted |
Reimplemented in core\form\persistent, and lesson_add_page_form_numerical.
|
inherited |
Adds an initialisation call for a standard JavaScript enhancement.
This function is designed to add an initialisation call for a JavaScript enhancement that should exist within javascript-static M.form.init_{enhancementname}.
Current options:
string | element | $element | form element for which Javascript needs to be initalized |
string | $enhancement | which init function should be called |
array | $options | options passed to javascript |
array | $strings | strings for javascript |
|
inherited |
Return true if a cancel button has been pressed resulting in the form being submitted.
bool | true if a cancel button has been pressed |
Reimplemented in base_moodleform.
|
inherited |
Check that form was submitted.
Does not check validity of submitted data.
bool | true if form properly submitted |
|
inherited |
Check that form data is valid.
You should almost always use this, rather than validate_defined_fields
bool | true if form data valid |
|
staticinherited |
Used by tests to generate valid submit keys for moodle forms that are submitted with ajax data.
moodle_exception | If called outside unit test environment |
array | $data | Existing form data you wish to add the keys to. |
array |
|
staticinherited |
Used by tests to simulate submitted form data submission from the user.
For form fields where no data is submitted the default for that field as set by set_data or setDefault will be passed to get_data.
This method sets $_POST or $_GET and $_FILES with the data supplied. Our unit test code empties all these global arrays after each test.
array | $simulatedsubmitteddata | An associative array of form values (same format as $_POST). |
array | $simulatedsubmittedfiles | An associative array of files uploaded (same format as $_FILES). Can be omitted. |
string | $method | 'post' or 'get', defaults to 'post'. |
null | $formidentifier | the default is to use the class name for this class but you may need to provide a different value here for some forms that are used more than once on the same page. |
|
inherited |
|
inherited |
|
inherited |
Checks if button pressed is not for submitting the form.
@staticvar bool $nosubmit keeps track of no submit button
bool |
|
inherited |
Checks if a parameter was passed in the previous form submission.
string | $name | the name of the page parameter we want |
mixed | $default | the default value to return if nothing is found |
string | $type | expected type of parameter |
mixed |
|
protectedinherited |
Extend the validation function from any other plugin.
stdClass | $data | The form data. |
array::$errors | The list of errors keyed by element name. |
|
inherited |
Renders the html form (same as display, but returns the result).
Note that you can only output this rendered result once per page, as it contains IDs which must be unique.
string | HTML code for the form |
|
inherited |
Method to add a repeating group of elements to a form.
array | $elementobjs | Array of elements or groups of elements that are to be repeated |
int | $repeats | no of times to repeat elements initially |
array | $options | a nested array. The first array key is the element name. the second array key is the type of option to set, and depend on that option, the value takes different forms. 'default' - default value to set. Can include '{no}' which is replaced by the repeat number. 'type' - PARAM_* type. 'helpbutton' - array containing the helpbutton params. 'disabledif' - array containing the disabledIf() arguments after the element name. 'rule' - array containing the addRule arguments after the element name. 'expanded' - whether this section of the form should be expanded by default. (Name be a header element.) 'advanced' - whether this element is hidden by 'Show more ...'. |
string | $repeathiddenname | name for hidden element storing no of repeats in this form |
string | $addfieldsname | name for button to add more fields |
int | $addfieldsno | how many fields to add at a time |
string | $addstring | name of button, {no} is replaced by no of blanks that will be added. |
bool | $addbuttoninside | if true, don't call closeHeaderBefore($addfieldsname). Default false. |
int | no of repeats of element in this page |
|
inherited |
Helper used by repeat_elements().
int | $i | the index of this element. |
HTML_QuickForm_element | $elementclone | |
array | $namecloned | array of names |
|
inherited |
Save file to standard filesystem.
string | $elname | name of element |
string | $pathname | full path name of file |
bool | $override | override file if exists |
bool | success |
|
inherited |
Save verified uploaded files into directory.
Upload process can be customised from definition()
string | $destination | path where file should be stored |
bool | Always false |
|
inherited |
Save file to local filesystem pool.
string | $elname | name of element |
int | $newcontextid | id of context |
string | $newcomponent | name of the component |
string | $newfilearea | name of file area |
int | $newitemid | item id |
string | $newfilepath | path of file where it get stored |
string | $newfilename | use specified filename, if not specified name of uploaded file used |
bool | $overwrite | overwrite file if exists |
int | $newuserid | new userid if required |
mixed | stored_file object or false if error; may throw exception if duplicate found |
|
inherited |
Returns a temporary file, do not forget to delete after not needed any more.
string | $elname | name of the elmenet |
string|bool | either string or false |
|
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).
mixed | $default_values | object or array of default values |
Reimplemented from moodleform.
Reimplemented in mod_lti_mod_form, and mod_scorm_mod_form.
|
inherited |
Set display mode for the form when labels take full width of the form and above the elements even on big screens.
Useful for forms displayed inside modals or in narrow containers
|
inherited |
Set the initial 'dirty' state of the form.
bool | $state |
|
protectedinherited |
Add an editor for an activity's introduction field.
null | $customlabel | Override default label for editor |
coding_exception |
|
inherited |
Validate the form.
You almost always want to call is_validated instead of this because it calls definition_after_data first, before validating the form, which is what you want in 99% of cases.
This is provided as a separate function for those special cases where you want the form validated before definition_after_data is called for example, to selectively add new elements depending on a no_submit_button press, but only when the form is valid when the no_submit_button is pressed,
bool | $validateonnosubmit | optional, defaults to false. The default behaviour is NOT to validate the form when a no submit button has been pressed. pass true here to override this behaviour |
bool | true if form data valid |
|
protectedinherited |
Internal method.
Validates filepicker and filemanager files if they are set as required fields. Also, sets the error message if encountered one.
bool|array | with errors |
mod_imscp_mod_form::validation | ( | $data, | |
$files | |||
) |
Perform minimal validation on the settings form.
array | $data | |
array | $files |
Reimplemented from moodleform_mod.
|
protectedinherited |
Course module record of the module that is being updated.
Will be null if this is an 'add' form and not an update one.
|
protectedinherited |
Instance of the module that is being updated.
This is the id of the {prefix}{modulename} record. Can be used in form definition. Will be "" if this is an 'add' form and not an update one.
|
protectedinherited |
Section of course that module instance will be put in or is in.
This is always the section number itself (column 'section' from 'course_sections' table).