. namespace core_course\hook; use course_edit_form; /** * Allows plugins to extend course form validation. * * @see course_edit_form::validation() * * @package core_course * @copyright 2023 Dmitrii Metelkin * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ #[\core\attribute\label('Allow plugins to extend a validation of the course editing form')] #[\core\attribute\tags('course')] class after_form_validation { /** * Plugin errors. * * @var array */ protected $errors = []; /** * Creates new hook. * * @param course_edit_form $formwrapper Course form wrapper.. * @param array $data Submitted data. * @param array $files Submitted files. */ 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 = [], ) { } /** * Returns submitted data. * * @return array */ public function get_data(): array { return $this->data; } /** * Returns submitted files. * * @return array */ public function get_files(): array { return $this->files; } /** * Return plugin generated errors. * * @return array */ public function get_errors(): array { return $this->errors; } /** * Plugins implementing a callback can add validation errors. * * @param array $errors Validation errors generated by a plugin. */ public function add_errors(array $errors): void { $this->errors = array_merge($this->errors, $errors); } }