Have a look at how it is done in the quiz code: https://github.com/moodle/moodle/blob/master/mod/quiz/edit.php#L113
Quiz
Code for Adding a question to an existing quiz
This discussion has been locked so you can no longer reply to it.
Have a look at how it is done in the quiz code: https://github.com/moodle/moodle/blob/master/mod/quiz/edit.php#L113