From 451e33c18c4dea049820bb53b21f527d233cb3b5 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 7 Mar 2024 22:23:21 +0800 Subject: [PATCH] MDL-81011 core_course: Update new course hooks to use attributes These hooks landed in the past week. Updating them to use the new attributes. --- course/classes/hook/after_form_definition.php | 66 ++++----------------- .../hook/after_form_definition_after_data.php | 67 ++++----------------- course/classes/hook/after_form_submission.php | 68 +++++---------------- course/classes/hook/after_form_validation.php | 69 ++++------------------ 4 files changed, 46 insertions(+), 224 deletions(-) diff --git a/course/classes/hook/after_form_definition.php b/course/classes/hook/after_form_definition.php index 63599b7a71b..277cdc17616 100644 --- a/course/classes/hook/after_form_definition.php +++ b/course/classes/hook/after_form_definition.php @@ -25,70 +25,24 @@ use MoodleQuickForm; * * @see course_edit_form::definition() * - * @package core + * @package core_course * @copyright 2023 Dmitrii Metelkin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class after_form_definition implements described_hook { - - /** - * Course form wrapper. - * - * @var course_edit_form - */ - protected $formwrapper; - - /** - * Form to be extended. - * - * @var \MoodleQuickForm - */ - protected $mform; - +#[\core\attribute\label('Allows plugins to extend course editing form')] +#[\core\attribute\tags('course')] +class after_form_definition { /** * Creates new hook. * * @param course_edit_form $formwrapper Course form wrapper. * @param MoodleQuickForm $mform Form to be extended. */ - public function __construct(course_edit_form $formwrapper, MoodleQuickForm $mform) { - $this->formwrapper = $formwrapper; - $this->mform = $mform; - } - - /** - * Returns form. - * - * @return MoodleQuickForm - */ - public function get_mform(): MoodleQuickForm { - return $this->mform; - } - - /** - * Returns form wrapper instance. - * - * @return course_edit_form - */ - public function get_formwrapper(): course_edit_form { - return $this->formwrapper; - } - - /** - * Describes the hook purpose. - * - * @return string - */ - public static function get_hook_description(): string { - return 'Allows plugins to extend course editing form'; - } - - /** - * List of tags that describe this hook. - * - * @return string[] - */ - public static function get_hook_tags(): array { - return ['course']; + public function __construct( + /** @var course_edit_form The form wrapper for the edit form */ + public readonly course_edit_form $formwrapper, + /** @var MoodlequickForm The form to be extended */ + public readonly MoodleQuickForm $mform, + ) { } } diff --git a/course/classes/hook/after_form_definition_after_data.php b/course/classes/hook/after_form_definition_after_data.php index 45f22165628..78ebae52956 100644 --- a/course/classes/hook/after_form_definition_after_data.php +++ b/course/classes/hook/after_form_definition_after_data.php @@ -16,7 +16,6 @@ namespace core_course\hook; -use core\hook\described_hook; use course_edit_form; use MoodleQuickForm; @@ -25,70 +24,24 @@ use MoodleQuickForm; * * @see course_edit_form::definition_after_data() * - * @package core + * @package core_course * @copyright 2023 Dmitrii Metelkin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class after_form_definition_after_data implements described_hook { - - /** - * Course form wrapper. - * - * @var course_edit_form - */ - protected $formwrapper; - - /** - * Form to be extended. - * - * @var \MoodleQuickForm - */ - protected $mform; - +#[\core\attribute\label('Allows plugins to extend course editing form after data is set')] +#[\core\attribute\tags('course')] +class after_form_definition_after_data { /** * Creates new hook. * * @param course_edit_form $formwrapper Course form wrapper.. * @param MoodleQuickForm $mform Form to be extended. */ - public function __construct(course_edit_form $formwrapper, MoodleQuickForm $mform) { - $this->formwrapper = $formwrapper; - $this->mform = $mform; - } - - /** - * Returns form. - * - * @return MoodleQuickForm - */ - public function get_mform(): MoodleQuickForm { - return $this->mform; - } - - /** - * Returns form wrapper instance. - * - * @return course_edit_form - */ - public function get_formwrapper(): course_edit_form { - return $this->formwrapper; - } - - /** - * Describes the hook purpose. - * - * @return string - */ - public static function get_hook_description(): string { - return 'Allows plugins to extend course editing form after data is set'; - } - - /** - * List of tags that describe this hook. - * - * @return string[] - */ - public static function get_hook_tags(): array { - return ['course']; + public function __construct( + /** @var course_edit_form The form wrapper for the edit form */ + public readonly course_edit_form $formwrapper, + /** @var MoodlequickForm The form to be extended */ + public readonly MoodleQuickForm $mform, + ) { } } diff --git a/course/classes/hook/after_form_submission.php b/course/classes/hook/after_form_submission.php index e51e4b95639..134a91cac05 100644 --- a/course/classes/hook/after_form_submission.php +++ b/course/classes/hook/after_form_submission.php @@ -16,79 +16,39 @@ namespace core_course\hook; -use core\hook\described_hook; -use stdClass; - /** * Allows plugins to extend course form submission. * * @see create_course() * @see update_course() * - * @package core + * @package core_course * @copyright 2023 Dmitrii Metelkin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class after_form_submission implements described_hook { - - /** - * Submitted data. - * - * @var stdClass - */ - protected $data; - - /** - * Is it a new course ? - * - * @var bool - */ - protected $isnewcourse = false; - +#[\core\attribute\label('Allows plugins to extend saving of the course editing form')] +#[\core\attribute\tags('course')] +class after_form_submission { /** * Creates new hook. * - * @param stdClass $data Submitted data. - * @param bool $isnewcourse Is it a new course? + * @param \stdClass $data Submitted data + * @param bool $isnewcourse Whether this is a new course */ - public function __construct(stdClass $data, bool $isnewcourse = false) { - $this->data = $data; - $this->isnewcourse = $isnewcourse; + public function __construct( + /** @var \stdClass The submitted data */ + protected \stdClass $data, + /** @var bool Whether this is a new course */ + public readonly bool $isnewcourse = false, + ) { } /** * Returns submitted data. * - * @return stdClass + * @return \stdClass */ - public function get_data(): stdClass { + public function get_data(): \stdClass { return $this->data; } - - /** - * Informs callbacks if a hook called for a new course. - * - * @return bool - */ - public function is_new_course(): bool { - return $this->isnewcourse; - } - - /** - * Describes the hook purpose. - * - * @return string - */ - public static function get_hook_description(): string { - return 'Allows plugins to extend saving of the course editing form'; - } - - /** - * List of tags that describe this hook. - * - * @return string[] - */ - public static function get_hook_tags(): array { - return ['course']; - } } diff --git a/course/classes/hook/after_form_validation.php b/course/classes/hook/after_form_validation.php index d6fae028620..754bb7cf308 100644 --- a/course/classes/hook/after_form_validation.php +++ b/course/classes/hook/after_form_validation.php @@ -16,7 +16,6 @@ namespace core_course\hook; -use core\hook\described_hook; use course_edit_form; /** @@ -24,33 +23,13 @@ use course_edit_form; * * @see course_edit_form::validation() * - * @package core + * @package core_course * @copyright 2023 Dmitrii Metelkin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class after_form_validation implements described_hook { - - /** - * Course form wrapper. - * - * @var course_edit_form - */ - protected $formwrapper; - - /** - * Submitted data. - * - * @var array - */ - protected $data = []; - - /** - * Submitted files. - * - * @var array - */ - protected $files = []; - +#[\core\attribute\label('Allow plugins to extend a validation of the course editing form')] +#[\core\attribute\tags('course')] +class after_form_validation { /** * Plugin errors. * @@ -65,19 +44,14 @@ class after_form_validation implements described_hook { * @param array $data Submitted data. * @param array $files Submitted files. */ - public function __construct(course_edit_form $formwrapper, array $data, array $files = []) { - $this->formwrapper = $formwrapper; - $this->data = $data; - $this->files = $files; - } - - /** - * Returns form wrapper instance. - * - * @return course_edit_form - */ - public function get_formwrapper(): course_edit_form { - return $this->formwrapper; + public function __construct( + /** @var course_edit_form Course form wrapper */ + public readonly course_edit_form $formwrapper, + /** @var array The submitted data */ + private array $data, + /** @var array Submitted files */ + private array $files = [], + ) { } /** @@ -111,27 +85,8 @@ class after_form_validation implements described_hook { * Plugins implementing a callback can add validation errors. * * @param array $errors Validation errors generated by a plugin. - * @return void */ public function add_errors(array $errors): void { $this->errors = array_merge($this->errors, $errors); } - - /** - * Describes the hook purpose. - * - * @return string - */ - public static function get_hook_description(): string { - return 'Allows plugins to extend a validation of the course editing form'; - } - - /** - * List of tags that describe this hook. - * - * @return string[] - */ - public static function get_hook_tags(): array { - return ['course']; - } } -- 2.11.4.GIT