Skip to main content
Version: main

Moodle 4.4 developer update

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

Core changes

Dependency Injection

Since 4.4

Support for PSR-11 compatible Containers has been introduced and can be accessed via the \core\di class. Read the full documentation for information on how to use Moodle's DI infrastructure.

String formatting

Deprecation of format_* parameters

A number of legacy features and ways of calling format_text, and format_string now emit deprecation notices. These were all deprecated a long time ago but did not emit:

  • Changes to format_string:
    • The $options array must not be a \context or \core\context object. This was never supported and behaviour was previously undetected
    • Unknown values passed to the $options parameter will now emit appropriate debugging notices
  • Changes to format_text:
    • The fourth parameter, $courseiddonotuse now emits a deprecation notice if provided. This was deprecated for Moodle 2.0 in MDL-22001
    • The smiley option now emits a deprecation notice. This was deprecated for Moodle 2.0.
    • The nocache option now emits a deprecation notice. This was deprecated for Moodle 2.3 in MDL-34347
    • The use of FORMAT_WIKI as a source format now throws an exception. Previously it added debugging information to the rendered content. This was deprecated in Moodle 1.5.
    • Unknown values passed to the $options parameter will now emit appropriate debugging notices

New \core\formatting class

Since 4.4

A new \core\formatting class has been introduced with new format_string(), and format_text() methods.

These methods no longer user the array $options style configuration, instead expanding options into method parameters.

note

The existing \format_string(), and \format_text() methods remain in place, and are not currently deprecated. At this time you do not need to migrate to the APIs.

New \core\formatting methods
namespace core;

class formatting {
public function format_string(
?string $string,
bool $striplinks = true,
?context $context = null,
bool $filter = true,
bool $escape = true,
): string;

public function format_text(
?string $text,
string $format = FORMAT_MOODLE,
?context $context = null,
bool $trusted = false,
?bool $clean = null,
bool $filter = true,
bool $para = true,
bool $newlines = true,
bool $overflowdiv = false,
bool $blanktarget = false,
bool $allowid = false,
): string;
}

If choosing to use these new methods you must use Dependency Injection either via injection into the class, or via the \core\di container. You must not instantiate the \core\formatting class directly.

Usage in an injected class
namespace core;

class example {
public function __construct(
protected readonly \core\formatting $formatter,
) {
}

public function do_something(string $input): string {
return $this->formatter->format_string($input, ...);
}
}
Named Parameters

It is strongly recommended that you make use of named parameters for all but the first argument when calling them, rather than using positional arguments.

Named arguments
$formatter = \core\di::get(\core\formatting::class);

$formatter->format_string(
"The content to be formatted",
context: \core\context\course::instance($courseid),
filter: false,
);

$formatter->format_text(
"The content to be formatted",
context: \core\context\course::instance($courseid),
filter: false,
blanktarget: true,
);

Enrolment

Support for multiple instances in csv course upload

Since 4.4

It is now possible to upload a CSV file with multiple enrol instances of the same type in same course. This is useful for example when you want to enrol users in a course using two different cohorts.

To support this, a new method has been added to allow the UI to locate existing enrolment instances:

/**
* Finds matching instances for a given course.
*
* @param array $enrolmentdata enrolment data.
* @param int $courseid Course ID.
* @return stdClass|null Matching instance
*/
public function find_instance(
array $enrolmentdata,
int $courseid,
) : ?stdClass;

If your enrolment plugins supports multiple instances within the same course, you should implement this method.

Format of the CSV file

Each line of the CSV should only have data for one enrolment instance.

best-example.csv
shortname,fullname,category_idnumber,enrolment_1,enrolment_1_role,enrolment_1_cohortidnumber
C1,Course 1,CAT1,cohort,student,CV1
C1,Course 1,CAT1,cohort,teacher,CV4
danger

If a single line format is used, only the final enrolment instance will be updated. For example in the following example only the second enrolment instance will be updated:

not-recommended-example.csv
shortname,fullname,category,summary,enrolment_1,enrolment_1_role,enrolment_2,enrolment_2_role
shortname,fullname,category,summary,cohort,student,cohort,teacher

Bootstrap preparations for version 5

Since 4.4

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. This will help us to upgrade to Bootstrap 5 in the future.

Badges

  • Badge colour class helpers .badge-* have been replaced with background utilities (use .bg-primary instead of .badge-primary) combined with the corresponding text colour classes (.text-dark or .text-white) to meet accessibility contrast.
  • The .badge-pill class has been replaced with .rounded-pill
Don't
<span class="badge badge-danger badge-pill">Error badge</span>
Do
<span class="badge bg-danger text-white rounded-pill">Error badge</span>

Media

The .media component has been replaced with utility classes.

Don't
<div class="media">
<div class="media-left">
[...]
</div>
<div class="media-body">
[...]
</div>
</div>
Do
<div class="d-flex">
<div class="flex-shrink-0">
[...]
</div>
<div class="flex-grow-1 ml-3">
[...]
</div>
</div>

Mixins

The following previously deprecated mixins will be dropped in BS5, so they can be refactored:

  • hover, hover-focus, plain-hover-focus and hover-focus-active
  • float-left, float-right and float-none
  • nav-divider
  • img-retina
  • text-hide
  • invisible
  • form-control-focus
  • text-emphasis-variant
  • size
  • make-container-max-widths
  • g-variant and bg-gradient-variant
Don't
.collapse-list-item {
padding: $collapse-list-item-padding-y $collapse-list-item-padding-x;
@include hover-focus() {
background-color: $collapse-list-item-hover-bg;
border-color: $collapse-list-item-hover-border;
}
}
Do
.collapse-list-item {
padding: $collapse-list-item-padding-y $collapse-list-item-padding-x;
&:hover,
&:focus {
background-color: $collapse-list-item-hover-bg;
border-color: $collapse-list-item-hover-border;
}
}

New course section page

Since 4.4

The new course/section.php page is designed exclusively for displaying individual section content. It only requires sectionid, eliminating the need for the legacy sectionnumber.

Enhancements to this page:

  • The General section will no longer appear above the selected section, ensuring a focused display of content for the specified section id.
  • Regardless of the Course layout ("All sections on one page" vs "One section per page"), all section names in the main course page content will now link to the new page (excluding editing mode).
  • The $CFG->linkcoursesections setting has been entirely removed. Initially used for the Classic theme to empower admins in deciding whether section names in the Navigation block should be linked, this setting is now obsolete. With the introduction of the course/section.php page, dedicated to displaying content for any single section, and a convenient link from the main course page, users can seamlessly focus on section content without the need for this setting.
  • The methods core_courseformat\base::set_section_number() and core_courseformat\base::get_section_number() have been deprecated and replaced by core_courseformat\base::set_sectionnum() and core_courseformat\base::get_sectionnum(). The new methods use the null value when all the sections must be displayed (instead of 0). That way, section 0 (General), can be displayed on a single page too.

Activity icons

Since 4.4

New designs

The activity icons have been updated to prioritize readability and transform the existing filled square shapes with white icons into outlined colored icons against a transparent background. This modification ensures that the icons are not only more accessible but also easily distinguishable for users. When upgrading the SVG files, the .png files have been removed.

Considerations for creating/updating SVG icons
  • Please make sure that the icons are filled with #212529 and that the background is transparent.
  • The icons should be 24x24px. It's recommended to define width and height into the SVG files to guarantee that the icons are displayed correctly.

New activity icons

Activity purposes

Since Moodle 4.0, in places like the course page and the activity chooser icons have a more prominent role which is defined using the FEATURE_MOD_PURPOSE feature flag.

The available activity purposes for this feature are:

  • Administration (MOD_PURPOSE_ADMINISTRATION)
  • Assessment (MOD_PURPOSE_ASSESSMENT)
  • Collaboration (MOD_PURPOSE_COLLABORATION)
  • Communication (MOD_PURPOSE_COMMUNICATION)
  • Interactive content (MOD_PURPOSE_INTERACTIVECONTENT)
  • Resource (MOD_PURPOSE_CONTENT)
  • Other (MOD_PURPOSE_OTHER)
Changes in purposes for Moodle 4.4
  • MOD_PURPOSE_INTERFACE has been deprecated, so it's not recommended to use it.
  • MOD_PURPOSE_INTERACTIVECONTENT has been added. In core, it's used for activities like H5P, Lesson, SCORM and IMS package.

Branded icons

A new callback, <modname>_is_branded() has been added to the modules. Branded icons are displayed with their original colours and they are not affected by the activity purpose colours. By default, none of the modules are branded.

/**
* Whether the activity is branded.
* This information is used, for instance, to decide if a filter should be applied to the icon or not.
*
* @return bool True if the activity is branded, false otherwise.
*/
function h5pactivity_is_branded(): bool {
return true;
}

Previous versions