Skip to content

Latest commit

 

History

History
12 lines (7 loc) · 3.73 KB

new-events.md

File metadata and controls

12 lines (7 loc) · 3.73 KB

Guide to Supporting New Events

Hello there, hopefully you've landed here gently after journeying through our guide to creating new statements, in which case you've already installed the plugin using Git, you've made a new Git branch for your changes, and you're aware that you're super awesome 😉.

With that all said, let's move swifly on. Hopefully you know which of the logstore events you want to use to create the statement. With that known, the first thing you need to do is create your transformer function in the /src/transformer/events directory. In that directory, you should notice that the sub directories represent the Moodle module (e.g. core, mod_assign, etc) and the files inside those directories are named with the event name (e.g. course_completed, course_viewed, etc). For example, the transformer function for the \core\event\course_completed logstore event is kept in the /src/transformer/events/core/course_completed.php file. Now following this pattern, we hope you're able to create a new PHP file with a transformer function for your event using the course_completed transformer function as an example. Make sure that the namespace matches the file path from the src directory and that the name of your function matches the event name.

Now that you've made your transformer function, you need to map the event to that transformer function in our get_event_function_map function. Use the logstore event as the key in the map and the path of the transfomer function as the value in the map. This will allow the transformer handler to pass the event and config to your new transformer function each time that logstore event is received by the handler.

With the map changed and transformer function created, you can go ahead and create your statement in the transformer function. Feel free to use the the course_completed transformer function again as an example. Whilst you're creating this function, you should be testing that the outputted statements are correct for a mocked version of the logstore event and Moodle data. To do this, you'll need to create a new directory for your test case in the /tests directory, you'll find that it's structured very similarly to the src/transformer directory. You should also notice that each test is made up of a directory containing 4 files, this is explained in our testing guide. Follow this pattern to create your own test cases and run ./vendor/bin/phpunit in your terminal from inside the plugin directory to execute your test cases.

When you're happy with your transformer function and all of your tests are passing ✅, it's time to commit your changes and make a pull request. To commit all of your changes you can run git add -A && git commit -am "A_DESCRIPTION_OF_YOUR_CHANGES && git push". To make a pull request you can follow Github's guide for creating a pull request from a fork. Once your pull request is made, your changes will be reviewed and merged by a maintainer.

Hopefully adding support for a new event has been a breeze, but if you've had some issues let us know by creating a new issue on our Github issue tracker and we'll try to make this guide more breezy. In either case, thanks for taking your time to improve this plugin ❤️ .