Hi Julien,
Nice to see you searched, and found a solution.
Now, what would be really helpfull, to have a chance to see it integrated in futur Moodle version, is to create a tracker issue, with the "Patch" label, to report all you've done.
Hope you'll find / take time for that.
Séverin
PS : you'll find information on the tracker in this documentation