Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Class: moodleform_mod  - X-Ref

This class adds extra methods to form wrapper specific to be used for module add / update forms
mod/{modname}/mod_form.php replaced deprecated mod/{modname}/mod.html Moodleform.

__construct($current, $section, $cm, $course)   X-Ref


moodleform_mod($current, $section, $cm, $course)   X-Ref
Old syntax of class constructor. Deprecated in PHP7.


Class: name  - X-Ref

get_current()   X-Ref
Get the current data for the form.

return: stdClass|null

get_instance()   X-Ref
Get the DB record for the current instance.

return: stdClass|null

get_section()   X-Ref
Get the course section number (relative).

return: int

get_course()   X-Ref
Get the course id.

return: int

get_coursemodule()   X-Ref
Get the course module object.

return: stdClass|null

get_context()   X-Ref
Return the course context for new modules, or the module context for existing modules.

return: context

get_features()   X-Ref
Return the features this module supports.

return: stdClass

init_features()   X-Ref
No description

data_preprocessing(&$default_values)   X-Ref
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.

param: array $default_values passed by reference

definition_after_data()   X-Ref
Each module which defines definition_after_data() must call this method using parent::definition_after_data();


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

plugin_extend_coursemodule_validation($data)   X-Ref
Extend the validation function from any other plugin.

param: stdClass $data The form data.
return: array $errors The list of errors keyed by element name.

set_data($default_values)   X-Ref
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).

param: mixed $default_values object or array of default values

standard_coursemodule_elements()   X-Ref
Adds all the standard elements to a form to edit the settings for an activity module.


add_rating_settings($mform, int $itemnumber)   X-Ref
Add rating settings.

param: moodleform_mod $mform
param: int $itemnumber

plugin_extend_coursemodule_standard_elements()   X-Ref
Plugins can extend the coursemodule settings form.


plugin_extend_coursemodule_definition_after_data()   X-Ref
Plugins can extend the coursemodule settings form after the data is set.


add_completion_rules()   X-Ref
Can be overridden to add custom completion rules if the module wishes
them. If overriding this, you should also override completion_rule_enabled.
<p>
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.

return: array Array of string IDs of added items, empty array if none

completion_rule_enabled($data)   X-Ref
Called during validation. Override to indicate, based on the data, whether
a custom completion rule is enabled (selected).

param: array $data Input data (not yet validated)
return: bool True if one or more rules is enabled, false if none are;

standard_hidden_coursemodule_elements()   X-Ref
No description

standard_grading_coursemodule_elements()   X-Ref
No description

add_intro_editor($required=null, $customlabel=null)   X-Ref
Add an editor for an activity's introduction field.

param: null $required Override system default for requiremodintro
param: null $customlabel Override default label for editor

standard_intro_elements($customlabel=null)   X-Ref
Add an editor for an activity's introduction field.

param: null $customlabel Override default label for editor

add_action_buttons($cancel=true, $submitlabel=null, $submit2label=null)   X-Ref
Overriding formslib's add_action_buttons() method, to add an extra submit "save changes and return" button.

param: bool $cancel show cancel button
param: string $submitlabel null means default, false means none, string is label text
param: string $submit2label  null means default, false means none, string is label text
return: void

apply_admin_locked_flags()   X-Ref
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.

return: void

apply_admin_defaults($datetimeoffsets = array()   X-Ref
Get the list of admin settings for this module and apply any defaults/advanced/locked/required settings.

param: $datetimeoffsets array - If passed, this is an array of fieldnames => times that the
return: void

data_postprocessing($data)   X-Ref
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.

param: stdClass $data passed by reference

get_data()   X-Ref
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.

return: object submitted data; NULL if not valid or not submitted or cancelled