# Guide to Supporting New Events
Hello there, hopefully you've landed here gently after journeying through [our guide to creating new statements](new-statements.md), in which case you've already [installed the plugin using Git](install-with-git.md), 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](https://docs.moodle.org/dev/Event_2#Existing_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](../src/transformer/events). 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](../src/transformer/events/core/course_completed.php). 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](../src/transformer/events/core/course_completed.php) 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](../src/transformer/get_event_function_map.php). 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](../src/transformer/handler.php) 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](../src/transformer/events/core/course_completed.php) 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](../tests), you'll find that it's structured very similarly to [the `src/transformer` directory](../src/transformer). You should also notice that each test is made up of a directory containing 4 files, this is explained in [our testing guide](testing.md). 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](https://help.github.com/articles/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](https://github.com/xAPI-vle/moodle-logstore_xapi/issues) and we'll try to make this guide more breezy. In either case, thanks for taking your time to improve this plugin ❤️ .