| 1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
namespace core_course\hook;
|
|
|
18 |
|
|
|
19 |
use course_edit_form;
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Allows plugins to extend course form validation.
|
|
|
23 |
*
|
|
|
24 |
* @see course_edit_form::validation()
|
|
|
25 |
*
|
|
|
26 |
* @package core_course
|
|
|
27 |
* @copyright 2023 Dmitrii Metelkin <dmitriim@catalyst-au.net>
|
|
|
28 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
29 |
*/
|
|
|
30 |
#[\core\attribute\label('Allow plugins to extend a validation of the course editing form')]
|
|
|
31 |
#[\core\attribute\tags('course')]
|
|
|
32 |
class after_form_validation {
|
|
|
33 |
/**
|
|
|
34 |
* Plugin errors.
|
|
|
35 |
*
|
|
|
36 |
* @var array
|
|
|
37 |
*/
|
|
|
38 |
protected $errors = [];
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* Creates new hook.
|
|
|
42 |
*
|
|
|
43 |
* @param course_edit_form $formwrapper Course form wrapper..
|
|
|
44 |
* @param array $data Submitted data.
|
|
|
45 |
* @param array $files Submitted files.
|
|
|
46 |
*/
|
|
|
47 |
public function __construct(
|
|
|
48 |
/** @var course_edit_form Course form wrapper */
|
|
|
49 |
public readonly course_edit_form $formwrapper,
|
|
|
50 |
/** @var array The submitted data */
|
|
|
51 |
private array $data,
|
|
|
52 |
/** @var array Submitted files */
|
|
|
53 |
private array $files = [],
|
|
|
54 |
) {
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
* Returns submitted data.
|
|
|
59 |
*
|
|
|
60 |
* @return array
|
|
|
61 |
*/
|
|
|
62 |
public function get_data(): array {
|
|
|
63 |
return $this->data;
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
/**
|
|
|
67 |
* Returns submitted files.
|
|
|
68 |
*
|
|
|
69 |
* @return array
|
|
|
70 |
*/
|
|
|
71 |
public function get_files(): array {
|
|
|
72 |
return $this->files;
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
/**
|
|
|
76 |
* Return plugin generated errors.
|
|
|
77 |
*
|
|
|
78 |
* @return array
|
|
|
79 |
*/
|
|
|
80 |
public function get_errors(): array {
|
|
|
81 |
return $this->errors;
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
/**
|
|
|
85 |
* Plugins implementing a callback can add validation errors.
|
|
|
86 |
*
|
|
|
87 |
* @param array $errors Validation errors generated by a plugin.
|
|
|
88 |
*/
|
|
|
89 |
public function add_errors(array $errors): void {
|
|
|
90 |
$this->errors = array_merge($this->errors, $errors);
|
|
|
91 |
}
|
|
|
92 |
}
|