Allow only a single instance of module in course

Allow only a single instance of module in course

by Benjamin Ellis -
Number of replies: 2
Picture of Particularly helpful Moodlers

This question has been asked before - https://moodle.org/mod/forum/discuss.php?d=331304 but no answer appears to have been suggested.  Since it was a while back - maybe someone has found a solution.  I supposed I could do something in add_instance but I rather not let the user see the option to add the module.

Average of ratings: -
In reply to Benjamin Ellis

Re: Allow only a single instance of module in course

by Darko Miletić -
You have two options here:

  • Alter the addinstance function of your activity to prevent creation of new instance. User will see the module in the dialog for adding new activity.
  • Create custom theme and in that theme override the course renderer method \core_course_renderer::course_section_add_cm_control since it is there where initialization of the course module list is performed. Adjust the code there to fit your purposes. Unfortunately only when using your custom theme will the user see desired behavior.

https://docs.moodle.org/dev/Overriding_a_renderer


Average of ratings: Useful (1)
In reply to Darko Miletić

Re: Allow only a single instance of module in course

by Benjamin Ellis -
Picture of Particularly helpful Moodlers

Looks like it will have to be the add_instance then sad Thanks Darko.