From b4816367b713d35017a72ccdcb38d56f5a3be37d Mon Sep 17 00:00:00 2001 From: Amaia Anabitarte Date: Tue, 7 Nov 2023 10:31:04 +0100 Subject: [PATCH] MDL-79862 completion: Improve error handling for default completion --- completion/classes/defaultedit_form.php | 10 +++++++++- completion/classes/edit_base_form.php | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/completion/classes/defaultedit_form.php b/completion/classes/defaultedit_form.php index a663622e7ed..8200723e5e8 100644 --- a/completion/classes/defaultedit_form.php +++ b/completion/classes/defaultedit_form.php @@ -129,7 +129,15 @@ class core_completion_defaultedit_form extends core_completion_edit_base_form { $this->get_suffix() ); $data = (array)$data; - $modform->data_preprocessing($data); + try { + $modform->data_preprocessing($data); + } catch (moodle_exception $e) { + debugging( + 'data_preprocessing function of module ' . $modnames[0] . + ' should be fixed so it can be shown together with other Default activity completion forms', + DEBUG_DEVELOPER + ); + } // Unset fields that will conflict with this form and set data to this form. unset($data['cmid']); unset($data['modids']); diff --git a/completion/classes/edit_base_form.php b/completion/classes/edit_base_form.php index d5ef8ff7017..ff2efd2f247 100644 --- a/completion/classes/edit_base_form.php +++ b/completion/classes/edit_base_form.php @@ -125,7 +125,9 @@ abstract class core_completion_edit_base_form extends moodleform { ' has wrong suffix and has been removed from the form. This has to be fixed by the developer', DEBUG_DEVELOPER ); - $moduleform->_form->removeElement($customcompletionelement); + if ($moduleform->_form->elementExists($customcompletionelement)) { + $moduleform->_form->removeElement($customcompletionelement); + } } } }