Skip to content

Commit

Permalink
[docs] Append a suffix to the completion rules
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed Aug 11, 2023
1 parent f4456bb commit ec439ea
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions docs/devupdate.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

:::

0 comments on commit ec439ea

Please sign in to comment.