Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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_ai\form;
18
 
19
use moodleform;
20
 
21
defined('MOODLE_INTERNAL') || die();
22
 
23
require_once($CFG->libdir . '/formslib.php');
24
 
25
/**
26
 * Generate action settings form.
27
 *
28
 * @package    core_ai
29
 * @copyright  2024 Matt Porritt <matt.porritt@moodle.com>
30
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31
 */
32
class action_settings_form extends moodleform {
33
    #[\Override]
34
    protected function definition() {
35
    }
36
 
37
    #[\Override]
38
    protected function after_definition() {
39
        parent::after_definition();
40
        $this->_form->_registerCancelButton('cancel');
41
    }
42
 
43
    #[\Override]
44
    public function definition_after_data() {
45
        // Dispatch a hook for plugins to add their fields.
46
        $hook = new \core_ai\hook\after_ai_action_settings_form_hook(
47
            mform: $this->_form,
48
            plugin: $this->_customdata['providername'],
49
        );
50
        \core\di::get(\core\hook\manager::class)->dispatch($hook);
51
        // Add action buttons.
52
        $this->add_action_buttons();
53
    }
54
 
55
    /**
56
     * Get the default values for the form.
57
     *
58
     * @return array
59
     */
60
    public function get_defaults(): array {
61
        $data = $this->_form->exportValues();
62
        unset(
63
            $data['sesskey'], // We do not need to return sesskey.
64
            $data['_qf__'.$this->_formname], // We do not need the submission marker.
65
            $data['provider'], // We do not need the provider.
66
            $data['providerid'], // We do not need the provider id.
67
            $data['action'] // We do not need the action.
68
        );
69
        if (empty($data)) {
70
            return [];
71
        } else {
72
            return $data;
73
        }
74
    }
75
}