From 4d5c4b471db887bc0cf82ca1c5e12a577ca3f967 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Wed, 23 Aug 2023 15:31:36 +0100 Subject: [PATCH] MDL-79144 hooks: allow hooks to return tags --- lib/classes/hook/described_hook.php | 7 +++++++ lib/classes/hooks.php | 1 + lib/tests/fixtures/hook/hook.php | 9 +++++++++ lib/tests/fixtures/hook/stoppablehook.php | 9 +++++++++ 4 files changed, 26 insertions(+) diff --git a/lib/classes/hook/described_hook.php b/lib/classes/hook/described_hook.php index 27d14dd847e..2d143f5d0aa 100644 --- a/lib/classes/hook/described_hook.php +++ b/lib/classes/hook/described_hook.php @@ -35,4 +35,11 @@ interface described_hook { * @return string */ public static function get_hook_description(): string; + + /** + * List of tags that describe this hook. + * + * @return string[] + */ + public static function get_hook_tags(): array; } diff --git a/lib/classes/hooks.php b/lib/classes/hooks.php index 81fc92aa9db..9b417c8947d 100644 --- a/lib/classes/hooks.php +++ b/lib/classes/hooks.php @@ -80,6 +80,7 @@ final class hooks implements \core\hook\discovery_agent { if (is_subclass_of($classname, \core\hook\described_hook::class)) { $hooks[$classname]['description'] = $classname::get_hook_description(); + $hooks[$classname]['tags'] = $classname::get_hook_tags(); } } diff --git a/lib/tests/fixtures/hook/hook.php b/lib/tests/fixtures/hook/hook.php index 0003aef41ae..754df5e96d5 100644 --- a/lib/tests/fixtures/hook/hook.php +++ b/lib/tests/fixtures/hook/hook.php @@ -41,4 +41,13 @@ final class hook implements public static function get_deprecated_plugin_callbacks(): array { return ['oldcallback']; } + + /** + * List of tags that describe this hook. + * + * @return string[] + */ + public static function get_hook_tags(): array { + return ['test']; + } } diff --git a/lib/tests/fixtures/hook/stoppablehook.php b/lib/tests/fixtures/hook/stoppablehook.php index 938b7787c3a..33d5d75fb8e 100644 --- a/lib/tests/fixtures/hook/stoppablehook.php +++ b/lib/tests/fixtures/hook/stoppablehook.php @@ -53,4 +53,13 @@ final class stoppablehook implements public function isPropagationStopped(): bool { return $this->stopped; } + + /** + * List of tags that describe this hook. + * + * @return string[] + */ + public static function get_hook_tags(): array { + return ['test']; + } }