MDL-78528 completion: Add suffix support to avoid duplicated ids

This commit is contained in:
Sara Arjona
2023-08-09 09:12:43 +02:00
parent d4d0483cb1
commit 274db7f747
6 changed files with 194 additions and 50 deletions
+13
View File
@@ -111,6 +111,19 @@ abstract class core_completion_edit_base_form extends moodleform {
$moduleform->_form = $this->_form;
if ($customcompletionelements = $moduleform->add_completion_rules()) {
$this->hascustomrules = true;
foreach ($customcompletionelements as $customcompletionelement) {
// Instead of checking for the suffix at the end of the element name, we need to check for its presence
// because some modules, like SCORM, are adding things at the end.
if (!str_contains($customcompletionelement, $this->get_suffix())) {
debugging(
'Custom completion rule ' . $customcompletionelement . ' of module ' . $modnames[0] .
' has wrong suffix and has been removed from the form. This has to be fixed by the developer',
DEBUG_DEVELOPER
);
$moduleform->_form->removeElement($customcompletionelement);
}
}
}
return $customcompletionelements;
} catch (Exception $e) {