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.
This commit is contained in:
Andrew Nicols 2024-03-07 22:23:21 +08:00 committed by Sara Arjona
parent 871aa5e978
commit 451e33c18c
No known key found for this signature in database
4 changed files with 46 additions and 224 deletions

View File

@ -25,70 +25,24 @@ use MoodleQuickForm;
*
* @see course_edit_form::definition()
*
* @package core
* @package core_course
* @copyright 2023 Dmitrii Metelkin <dmitriim@catalyst-au.net>
* @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,
) {
}
}

View File

@ -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 <dmitriim@catalyst-au.net>
* @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,
) {
}
}

View File

@ -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 <dmitriim@catalyst-au.net>
* @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'];
}
}

View File

@ -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 <dmitriim@catalyst-au.net>
* @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'];
}
}