mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-81180 core: Add support for array notation in hook callback
This commit is contained in:
parent
6231d9119d
commit
bbc98c82c0
@ -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,
|
||||
],
|
||||
];
|
||||
|
@ -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;
|
||||
|
2
lib/tests/fixtures/hook/hooks1_valid.php
vendored
2
lib/tests/fixtures/hook/hooks1_valid.php
vendored
@ -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'],
|
||||
],
|
||||
];
|
||||
|
Loading…
x
Reference in New Issue
Block a user