Moodle APIs 4.3
Moodle 4.3.6 (Build: 20240812)
core_completion_defaultedit_form Class Reference

Default activity completion form. More...

Inheritance diagram for core_completion_defaultedit_form:

Public Member Functions

 __construct ( $action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true, $ajaxformdata=null)
 The constructor function calls the abstract function definition() and it will then process and clean and attempt to validate incoming data.
 
 _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_completiongrade_rules ()
 If all selected modules are of the same module type, adds custom completion rules from this module type.
 
 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.
 
 definition ()
 Form definition,.
 
 definition_after_data ()
 Each module which defines definition_after_data() must call this method.
 
 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_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.
 
 has_custom_completion_rules ()
 Returns if this form has custom completion rules.
 
 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.
 
 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 ($default_values)
 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)
 Form 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.
 

Protected Member Functions

 _get_post_params ()
 Internal method - should not be used anywhere.
 
 add_completion_rules ()
 If all selected modules are of the same module type, adds custom completion rules from this module type.
 
 add_custom_completion (string $function)
 If all selected modules are of the same module type, adds custom completion rules from this module type.
 
 after_definition ()
 After definition hook.
 
 completion_rule_enabled ($data)
 Checks if at least one of the custom completion rules is enabled.
 
 get_array_value_by_keys (array $array, array $keys)
 Returns an element of multi-dimensional array given the list of keys.
 
 get_cm ()
 Return the course module of the form, if any.
 
 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 ()
 This method has been overridden because the form identifier must be unique for each module type.
 
 get_module_form ()
 Returns an instance of component-specific module form for the first selected module.
 
 get_module_name ()
 Get the module name.
 
 get_module_names ()
 Returns list of types of selected modules.
 
 get_modules_with_hidden_rules ()
 Returns list of modules that have automatic completion rules that are not shown on this form (because they are not present in at least one other selected module).
 
 support_grades ()
 Returns true if all selected modules support grading.
 
 support_views ()
 Returns true if all selected modules support tracking view.
 
 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
 
array $_modnames
 
moodleform_mod $_moduleform = null
 Do not use directly, call $this->get_module_form()
 
bool null $_validated = null
 stores the validation result of this form or null if not yet validated
 
stdClass $course
 
bool $hascustomrules = false
 
array $modules
 

Static Protected Attributes

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

Detailed Description

Default activity completion form.

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

Constructor & Destructor Documentation

◆ __construct()

core_completion_defaultedit_form::__construct ( $action = null,
$customdata = null,
$method = 'post',
$target = '',
$attributes = null,
$editable = true,
$ajaxformdata = null )

The constructor function calls the abstract function definition() and it will then process and clean and attempt to validate incoming data.

It will call your custom validate method to validate data and will also check any rules you have specified in definition using addRule

The name of the form (id attribute of the form) is automatically generated depending on the name you gave the class extending moodleform. You should call your class something like

Parameters
mixed$actionthe action attribute for the form. If empty defaults to auto detect the current url. If a moodle_url object then outputs params as hidden variables.
mixed$customdataif your form defintion method needs access to data such as $course $cm, etc. to construct the form definition then pass it in this array. You can use globals for somethings.
string$methodif you set this to anything other than 'post' then _GET and _POST will be merged and used as incoming data to the form.
string$targettarget frame for form submission. You will rarely use this. Don't use it if you don't need to as the target attribute is deprecated in xhtml strict.
mixed$attributesyou can pass a string of html attributes here or an array. Special attribute 'data-random-ids' will randomise generated elements ids. This is necessary when there are several forms on the same page. Special attribute 'data-double-submit-protection' set to 'off' will turn off double-submit protection JavaScript - this may be necessary if your form sends downloadable files in response to a submit button, and can't call core_form\util\form_download_complete();
bool$editable
array$ajaxformdataForms submitted via ajax, must pass their data here, instead of relying on _GET and _POST.

Reimplemented from moodleform.

Member Function Documentation

◆ add_completion_rules()

core_completion_edit_base_form::add_completion_rules ( )
protectedinherited

If all selected modules are of the same module type, adds custom completion rules from this module type.

Return values
array

◆ add_completiongrade_rules()

core_completion_edit_base_form::add_completiongrade_rules ( )
inherited

If all selected modules are of the same module type, adds custom completion rules from this module type.

Return values
array

◆ add_custom_completion()

core_completion_edit_base_form::add_custom_completion ( string $function)
protectedinherited

If all selected modules are of the same module type, adds custom completion rules from this module type.

Return values
array

◆ completion_rule_enabled()

core_completion_edit_base_form::completion_rule_enabled ( $data)
protectedinherited

Checks if at least one of the custom completion rules is enabled.

Parameters
array$dataInput data (not yet validated)
Return values
boolTrue if one or more rules is enabled, false if none are; default returns false

◆ definition()

core_completion_defaultedit_form::definition ( )

Form definition,.

Reimplemented from core_completion_edit_base_form.

◆ definition_after_data()

core_completion_edit_base_form::definition_after_data ( )
inherited

Each module which defines definition_after_data() must call this method.

Reimplemented from moodleform.

◆ get_cm()

core_completion_edit_base_form::get_cm ( )
protectedinherited

Return the course module of the form, if any.

Return values
cm_info|null

Reimplemented in core_completion_bulkedit_form.

◆ get_data()

core_completion_edit_base_form::get_data ( )
inherited

Return submitted data if properly submitted or returns NULL if validation fails or if there is no submitted data.

Return values
objectsubmitted data; NULL if not valid or not submitted or cancelled

Reimplemented from moodleform.

◆ get_form_identifier()

core_completion_defaultedit_form::get_form_identifier ( )
protected

This method has been overridden because the form identifier must be unique for each module type.

Otherwise, the form will display the same data for each module type once it's submitted.

Reimplemented from moodleform.

◆ get_module_form()

core_completion_defaultedit_form::get_module_form ( )
protected

Returns an instance of component-specific module form for the first selected module.

Return values
moodleform_mod|null

Reimplemented from core_completion_edit_base_form.

◆ get_module_name()

core_completion_edit_base_form::get_module_name ( )
protectedinherited

Get the module name.

If the form have more than one modules, it will return the first one.

Return values
string|nullThe module name or null if there is no modules associated to this form.

◆ get_module_names()

core_completion_defaultedit_form::get_module_names ( )
protected

Returns list of types of selected modules.

Return values
arraymodname=>modfullname

Reimplemented from core_completion_edit_base_form.

◆ get_modules_with_hidden_rules()

core_completion_edit_base_form::get_modules_with_hidden_rules ( )
protectedinherited

Returns list of modules that have automatic completion rules that are not shown on this form (because they are not present in at least one other selected module).

Return values
array

◆ has_custom_completion_rules()

core_completion_edit_base_form::has_custom_completion_rules ( )
inherited

Returns if this form has custom completion rules.

This is only possible if all selected modules have the same module type and this module type supports custom completion rules

Return values
bool

◆ support_grades()

core_completion_edit_base_form::support_grades ( )
protectedinherited

Returns true if all selected modules support grading.

Return values
bool

◆ support_views()

core_completion_edit_base_form::support_views ( )
protectedinherited

Returns true if all selected modules support tracking view.

Return values
bool

◆ validation()

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

Form validation.

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 moodleform.

Reimplemented in core_completion_bulkedit_form.


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