Another thing I have noticed during the review is that altough some of that logic handles course calendar header creation (eg. to display Calendar: Course shortname), it is not possible to get that through the UI, the only way to see the course calendar is by adding course parameter to the url. Not sure if there's a bug for that in Tracker, but also think it's important to mention here.
I'm adding Laurent proposed solution here for the records. https://github.com/laurentdavid/moodle/compare/fee1b8ce5f...MDL-76075-master