Skip to main content
Version: main (4.5)

Moodle 4.5 developer update

This page highlights the important changes that are coming in Moodle 4.5 for developers.

Badges

Deprecated badges/newbadge.php

The badges/newbadge.php and badges/edit.php pages have been combined to make things easier to maintain since both were pretty similar (newbadge.php for creating badges and edit.php for editing them).

As a result, badges/newbadge.php is now deprecated and will be removed in Moodle 6.0. Please update your code to use badges/edit.php instead.

Core changes

Autoloader

ABORT_AFTER_CONFIG

Since 4.5

Prior to Moodle 4.5 only a small number of classes were compatible with scripts using the ABORT_AFTER_CONFIG constant.

MDL-80275 modifies the location of the class Autoloader in the Moodle bootstrap to make it available to scripts using the ABORT_AFTER_CONFIG constant.

note

Please note that the same limitations regarding access to the Database, Session, and similar resources still exist.

Autoloading legacy classes

Since 4.5

The Moodle class autoloader is now able to load legacy classes defined in the relevant db/legacyclasses.php. Files should only contain a single class.

Example entry in lib/db/legacyclasses.php
$legacyclasses = [
// The legacy \moodle_exception class can be loaded from lib/classes/exception/moodle_exception.php.
\moodle_exception::class => 'exception/moodle_exception.php',

// The legacy \cache class can be loaded from cache/classes/cache.php.
\cache::class => [
'core_cache',
'cache.php',
],
];

See MDL-81919 for further information on the rationale behind this change.

SMS API

A new SMS API was introduced. See the SMS API documentation for more information.

Course

Reset course page

The reset course page has been improved. The words "Delete", and "Remove" have been removed from all options to make it easier to focus on the type of data to be removed and avoid inconsistencies and duplicated information. Third party plugins implementing reset methods might need to:

  • Add static element in the _reset_course_form_definition method before all the options with the Delete string:

    $mform->addElement('static', 'assigndelete', get_string('delete'));
  • Review all the strings used in the reset page to remove the Delete or Remove words from them.

caution

Starting from Moodle 4.5, the Reset course page form defined in the _reset_course_form_definition method should be reviewed because their options should not contain the Delete or Remove words. Check changes in any of the core plugins that implement the reset course method.

Filter Plugins

Since 4.5

Filter plugins and the Filter API have been updated to use the standard Moodle Class Autoloading infrastructure.

To ensure that your plugin continues to work in Moodle 4.5, you should move the filter_[pluginname] class located in filter/[pluginname]/filter.php to filter/[pluginname]/classes/text_filter.php, setting the namespace to filter_[pluginname] and renaming the class to text_filter.

Codebases supporting multiple versions of Moodle

If your codebase also supports Moodle 4.4 and earlier then you will also need to create a file in the 'old' location (filter/[pluginname]/filter.php) with the following content:

filter/[pluginname]/filter.php
class_alias(\filter_[pluginname]\text_filter::class, \filter_[pluginname]::class);

This will ensure that the plugin class is available at both the old and new locations.

TinyMCE plugins

The helplinktext language string is no longer required by editor plugins, instead the pluginname will be used in the help dialogue

Theme

Context header

Since 4.5

The method core_renderer::render_context_header($contextheader) has been deprecated, core_renderer::render($contextheader) should be used instead.

Plugins can still modify the context header by:

  • Overriding core_renderer::context_header() method in their class extending core_renderer
  • Adding core_renderer::render_context_header() method to their class extending core_renderer
  • Overriding the core/context_header.mustache template
theme/example/classes/output/core_renderer.php
class core_renderer extends \core_renderer {
[...]
public function context_header($headerinfo = null, $headinglevel = 1): string {
$output = parent::context_header($headerinfo, $headinglevel);
return $output . '<div class="badge badge-info">Hi!</div>';
}
[...]
}

Refactoring BS4 features dropped in BS5 using a "bridge"

Since 4.5

Some of the Bootstrap 4 classes will be deprecated or dropped in its version 5. To prepare for this, some of the current Bootstrap 4 classes usages have been replaced with version 5 compatible classes using a "bridge". This will help us to upgrade to Bootstrap 5 in the future.

See more information in Bootstrap 5 migration.