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_admin\admin;
18
 
19
use admin_setting;
20
 
21
/**
22
 * Render a template as part of other admin settings.
23
 * Use for rendering additional html in settings.
24
 *
25
 * @package    core_admin
26
 * @subpackage admin
27
 * @copyright  2024 Matt Porritt <matt.porritt@moodle.com>
28
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 */
30
class admin_setting_template_render extends admin_setting {
31
    /**
32
     * Constructor.
33
     *
34
     * @param string $name The name of the setting.
35
     * @param string $templatename The name of the template to render.
36
     * @param array|\stdClass $context The context to pass to the template.
37
     */
38
    public function __construct(
39
        string $name,
40
        /** @var string The name of the template to render. */
41
        protected string $templatename,
42
        /** @var array|\stdClass The context to pass to the template. */
43
        protected array|\stdClass $context
44
    ) {
45
        $this->nosave = true;
46
 
47
        parent::__construct($name, $templatename, '', '');
48
    }
49
 
50
    #[\Override]
51
    public function get_setting(): bool {
52
        return true;
53
    }
54
 
55
    #[\Override]
56
    public function get_defaultsetting(): bool {
57
        return true;
58
    }
59
 
60
    #[\Override]
61
    // phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
62
    public function write_setting($data): string {
63
        // Do not write any setting.
64
        return '';
65
    }
66
 
67
    #[\Override]
68
    public function output_html($data, $query = ''): string {
69
        global $OUTPUT;
70
 
71
        return $OUTPUT->render_from_template($this->templatename, $this->context);
72
    }
73
}