MDL-81180 core: Add support for array notation in hook callback

This commit is contained in:
Andrew Nicols
2024-03-11 16:49:54 +08:00
parent 6231d9119d
commit bbc98c82c0
3 changed files with 10 additions and 3 deletions
+2 -2
View File
@@ -26,8 +26,8 @@ defined('MOODLE_INTERNAL') || die();
$callbacks = [
[
'hook' => core\hook\output\standard_head_html_prepend::class,
'callback' => 'tool_mobile\local\hooks\output\standard_head_html_prepend::callback',
'hook' => \core\hook\output\standard_head_html_prepend::class,
'callback' => [\tool_mobile\local\hooks\output\standard_head_html_prepend::class, 'callback'],
'priority' => 0,
],
];
+7
View File
@@ -546,6 +546,13 @@ final class manager implements
return null;
}
$classmethod = $callback['callback'];
if (is_array($classmethod)) {
if (count($classmethod) !== 2) {
debugging("Hook callback definition contains invalid 'callback' array in '$component'", DEBUG_DEVELOPER);
return null;
}
$classmethod = implode('::', $classmethod);
}
if (!is_string($classmethod)) {
debugging("Hook callback definition contains invalid 'callback' string in '$component'", DEBUG_DEVELOPER);
return null;
+1 -1
View File
@@ -28,6 +28,6 @@ defined('MOODLE_INTERNAL') || die();
$callbacks = [
[
'hook' => 'test_plugin\\hook\\hook',
'callback' => 'test_plugin\\callbacks::test1',
'callback' => [\test_plugin\callbacks::class, 'test1'],
],
];