diff --git a/mod_form.php b/mod_form.php index 26fcd227..0db17b4c 100644 --- a/mod_form.php +++ b/mod_form.php @@ -195,10 +195,12 @@ public function validation($data, $files) { } /** - * Add any completion rules for the form. - * @return string[] + * Returns the suffixed name for custom completion elements. + * + * @param string $fieldname + * @return string */ - public function add_completion_rules() { + protected function get_suffixed_name(string $fieldname): string { global $CFG; // Changes for Moodle 4.3 - MDL-78516. @@ -207,11 +209,18 @@ public function add_completion_rules() { } else { $suffix = $this->get_suffix(); } + return $fieldname . $suffix; + } + /** + * Add any completion rules for the form. + * @return string[] + */ + public function add_completion_rules() { $mform =& $this->_form; - $mform->addElement('checkbox', 'completionsubmit' . $suffix, '', + $mform->addElement('checkbox', $this->get_suffixed_name('completionsubmit'), '', get_string('completionsubmit', 'questionnaire')); - return ['completionsubmit' . $suffix]; + return [$this->get_suffixed_name('completionsubmit')]; } /** @@ -220,7 +229,7 @@ public function add_completion_rules() { * @return bool */ public function completion_rule_enabled($data) { - return !empty($data['completionsubmit']); + return !empty($data[$this->get_suffixed_name('completionsubmit')]); } }