From e1ceccf93e7609db5d40f70bbedd12382c568066 Mon Sep 17 00:00:00 2001 From: Stefan Hanauska Date: Tue, 13 Feb 2024 09:18:27 +0100 Subject: [PATCH] MBS-8801: Add suffix for default completion --- mod_form.php | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/mod_form.php b/mod_form.php index cc00f3a9..43113179 100644 --- a/mod_form.php +++ b/mod_form.php @@ -71,7 +71,10 @@ public function definition(): void { * @return bool */ public function completion_rule_enabled($data): bool { - return (!empty($data['completioncreate']) || !empty($data['completioncomplete'])); + return ( + !empty($data['completioncreate' . $this->get_suffix()]) || + !empty($data['completioncomplete' . $this->get_suffix()]) + ); } /** @@ -82,22 +85,38 @@ public function completion_rule_enabled($data): bool { public function add_completion_rules(): array { $mform = $this->_form; + $completioncreate = 'completioncreate' . $this->get_suffix(); + $completioncomplete = 'completioncomplete' . $this->get_suffix(); + $mform->addElement( 'text', - 'completioncreate', + $completioncreate, get_string('completioncreate', 'kanban'), ['size' => 3] ); - $mform->setType('completioncreate', PARAM_INT); + $mform->setType($completioncreate, PARAM_INT); $mform->addElement( 'text', - 'completioncomplete', + $completioncomplete, get_string('completioncomplete', 'kanban'), ['size' => 3] ); - $mform->setType('completioncomplete', PARAM_INT); + $mform->setType($completioncomplete, PARAM_INT); + + return ([$completioncreate, $completioncomplete]); + } - return (['completioncreate', 'completioncomplete']); + /** + * Get the suffix to be added to the completion elements when creating them. + * This acts as a spare for compatibility with Moodle 4.1 and 4.2. + * + * @return string The suffix + */ + public function get_suffix(): string { + if (method_exists(get_parent_class($this), 'get_suffix')) { + return parent::get_suffix(); + } + return ''; } }