mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-75074 core_courseformat: Output classes are not inherited
If you have one course format that extends another one, any course format output classes that are not defined in the child format will now inherit from the parent (instead of from the base class as before).
This commit is contained in:
parent
24f97edd91
commit
f696590f0a
1 changed files with 20 additions and 8 deletions
|
@ -1273,16 +1273,28 @@ abstract class base {
|
|||
public function get_output_classname(string $outputname): string {
|
||||
// The core output class.
|
||||
$baseclass = "core_courseformat\\output\\local\\$outputname";
|
||||
// Check if there is a specific format class.
|
||||
$component = 'format_'. $this->get_format();
|
||||
$outputclass = "$component\\output\\courseformat\\$outputname";
|
||||
if (class_exists($outputclass)) {
|
||||
// Check that the outputclass is a subclass of the base class.
|
||||
if (!is_subclass_of($outputclass, $baseclass)) {
|
||||
throw new coding_exception("The \"$outputclass\" must extend \"$baseclass\"");
|
||||
|
||||
// Look in this format and any parent formats before we get to the base one.
|
||||
$classes = array_merge([get_class($this)], class_parents($this));
|
||||
foreach ($classes as $component) {
|
||||
if ($component === self::class) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Because course formats are in the root namespace, there is no need to process the
|
||||
// class name - it is already a Frankenstyle component name beginning 'format_'.
|
||||
|
||||
// Check if there is a specific class in this format.
|
||||
$outputclass = "$component\\output\\courseformat\\$outputname";
|
||||
if (class_exists($outputclass)) {
|
||||
// Check that the outputclass is a subclass of the base class.
|
||||
if (!is_subclass_of($outputclass, $baseclass)) {
|
||||
throw new coding_exception("The \"$outputclass\" must extend \"$baseclass\"");
|
||||
}
|
||||
return $outputclass;
|
||||
}
|
||||
return $outputclass;
|
||||
}
|
||||
|
||||
return $baseclass;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue