From ec439eab642161500399fdc84b3d87a928ded861 Mon Sep 17 00:00:00 2001 From: Sara Arjona Date: Fri, 11 Aug 2023 14:18:54 +0200 Subject: [PATCH] [docs] Append a suffix to the completion rules --- docs/devupdate.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/docs/devupdate.md b/docs/devupdate.md index c531c9b005..142049144c 100644 --- a/docs/devupdate.md +++ b/docs/devupdate.md @@ -334,3 +334,48 @@ if (!empty($showonly)) { $mform->filter_shown_headers(explode(',', $showonly)); } ``` + +## Activity completion + +### Append a suffix to the completion rules + +As part of [MDL-78516](https://tracker.moodle.org/browse/MDL-78516), the [Default completion form](https://docs.moodle.org/en/Activity_completion_settings#Changing_activity_completion_settings_in_bulk) has undergone a significant rebuild to enhance code reusability and maintainability. To prevent duplicate IDs, a suffix has been introduced to the form elements related to completion rules. + +For third-party plugins, an adjustment is needed to incorporate this new suffix, following the approach already taken by [core modules](https://github.com/sarjona/moodle/commit/8f57f0fdaca027c7099bc6966467077aecbc0862). + +The primary modification entails editing `mod/yourplugin/mod_form.php` and applying the suffix to the completion rule elements within all relevant methods. As an example, here are the changes made to the `mod/choice` module: + +```php + public function add_completion_rules() { + $mform =& $this->_form; + + $suffix = $this->get_suffix(); + $completionsubmitel = 'completionsubmit' . $suffix; + $mform->addElement('checkbox', $completionsubmitel, '', get_string('completionsubmit', 'choice')); + // Enable this completion rule by default. + $mform->setDefault($completionsubmitel, 1); + return [$completionsubmitel]; + } + + public function completion_rule_enabled($data) { + $suffix = $this->get_suffix(); + return !empty($data['completionsubmit' . $suffix]); + } + + public function data_postprocessing($data) { + parent::data_postprocessing($data); + // Set up completion section even if checkbox is not ticked. + if (!empty($data->completionunlocked)) { + $suffix = $this->get_suffix(); + if (empty($data->{'completionsubmit' . $suffix})) { + $data->{'completionsubmit' . $suffix} = 0; + } + } + } +``` + +:::caution + +Starting from Moodle 4.3, completion rules without the suffix will be phased out from the [Default completion form](https://docs.moodle.org/en/Activity_completion_settings#Changing_activity_completion_settings_in_bulk) until they are updated to incorporate the required suffix + +:::