Files
moodle/course/classes/hook/after_form_validation.php
T
2024-02-23 09:27:32 +11:00

138 lines
3.2 KiB
PHP

<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core_course\hook;
use core\hook\described_hook;
use course_edit_form;
/**
* Allows plugins to extend course form validation.
*
* @see course_edit_form::validation()
*
* @package core
* @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 = [];
/**
* 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(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;
}
/**
* 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.
* @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'];
}
}