From 10cef5e61133bdf2f72a8d2e36de4ceeafd8f329 Mon Sep 17 00:00:00 2001 From: Safat Date: Mon, 10 Nov 2025 21:37:33 +1100 Subject: [PATCH] MDL-85235 core: Add extend url hook --- lib/classes/hook/output/extend_url.php | 65 ++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 lib/classes/hook/output/extend_url.php diff --git a/lib/classes/hook/output/extend_url.php b/lib/classes/hook/output/extend_url.php new file mode 100644 index 00000000000..b6fa360c442 --- /dev/null +++ b/lib/classes/hook/output/extend_url.php @@ -0,0 +1,65 @@ +. + +namespace core\hook\output; + +use moodle_url; + +/** + * Allow augmentation of the moodle URL. + * + * The hook carries a mutable moodle_url. Callbacks can add query params. + * + * @package core + * @copyright 2025 Safat Shahin + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +#[\core\attribute\label('Allow augmentation of the moodle URL')] +#[\core\attribute\tags('output')] +final class extend_url { + /** + * Create a new instance of the hook. + * + * @param moodle_url $url The url of the page + */ + public function __construct( + /** @var moodle_url The url of the page */ + private moodle_url $url, + ) { + } + + /** + * Get the URL being modified. + * + * @return moodle_url + */ + public function get_url(): moodle_url { + return $this->url; + } + + /** + * Add a query parameter to the URL. + * + * @param string $name The name of the parameter + * @param string $value The value of the parameter + */ + public function add_param( + string $name, + string $value, + ): void { + $this->url->param($name, $value); + } +}