Core changes to External API

Core changes to External API

by Andrew Lyons -
Number of replies: 0
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi everybody,

This morning, MDL-76583 landed as a part of a mini project I've been working on to reduce some parts of our technical debt. This issue started as a small proof-of-concept in response to a question posed by Tim Hunt recently on how best to refactor parts of core.

This issue is a refactor of Moodle's External API in a backwards-compatible way and should allow autoloading of all of the core External API classes and functions.

The changes are, of course, documented.

It is worth noting that, at the moment, there is no deprecation notice if you continue to use the old API. This is deliberate and is an experiment into a delayed deprecation process that we may use when refactoring some widely-used Core APIs. The intent in this case is to emit a deprecation notice on these APIs from Moodle 4.6 onwards.

When Moodle 4.6 is released, all stable versions of Moodle will support the new namespaces. The only security-supported release which will not support them will be the outgoing Moodle 4.1 LTS release which will only be supported for a further six months.

The hope is that this will allow plugin developers to continue supporting a single codebase for multiple Moodle versions.

What does this mean for me now?

If you are writing an external service function for your own plugin, then you have a choice:

  • do nothing now. Your plugins will continue to work exactly as before until Moodle 4.6, at which point you can make some very minor changes to use the new API locations
  • update your code to use the new API locations now, but you will have to fork your plugin for older versions of Moodle.

If you are working on an external service for Moodle core, we strongly encourage you to use the new API locations. At the moment we do not emit any deprecation warnings, but I am considering ways to make this optionally emit a relevant deprecation notice for future deprecations.

If you are writing a new plugin for Moodle 4.2 and later only, we encourage you to use the new API locations immediately.

In the future

When we do finalise the deprecation in Moodle 4.6 the deprecation is easy:

  • alias the new class locations
  • stop manually requiring or including lib/externallib.php

Useful links

Best wishes,

Andrew Lyons

Average of ratings: Useful (4)