mudrd8mz / moodle-tool_pluginskel

Generator of Moodle plugins skeletons
https://moodle.org/plugins/tool_pluginskel
Other
51 stars 46 forks source link

\mod_XXX\event\course_module_viewed #83

Closed tmuras closed 3 years ago

tmuras commented 6 years ago

view.php generated for module refers to \mod_XXX\event\course_module_viewed class: https://github.com/mudrd8mz/moodle-tool_pluginskel/blob/master/skel/file/mod/view.mustache#L36

but the class is not generated. Therefore the view.php of the module generated will trigger the error:

Exception - Class 'mod_php\event\course_module_viewed' not found

dvdcastro commented 6 years ago

I had to add these events when creating a mod_* kind of plugin.

events:
    - eventname: course_module_instance_list_viewed
      extends: \core\event\course_module_instance_list_viewed
    - eventname: course_module_viewed
      extends: \core\event\course_module_viewed

They should be suggested, I agree.

mudrd8mz commented 5 years ago

Suggested fix:

  1. Introduce a new manager method verify_events_exist() similar to the existing verify_strings_exist()
  2. Use it in the prepare_mod_files() to make sure that the $this->recipe contains these two events, referenced from view.php and index.php
mudrd8mz commented 3 years ago

For now, the generator will raise warning if the event is missing in the recipe, and the example.yaml has it documented as needed.

For the future, we can try and auto-inject all implicit requirements like this.