Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
namespace mod_bigbluebuttonbn\form;
17
 
18
use MoodleQuickForm_text;
19
 
20
defined('MOODLE_INTERNAL') || die();
21
global $CFG;
22
require_once("$CFG->libdir/form/text.php");
23
 
24
/**
25
 * Text type form element with a copy widget
26
 *
27
 * Contains HTML class for a text type element and a link that will copy its content in the copy/paste buffer
28
 *
29
 * @package   mod_bigbluebuttonbn
30
 * @copyright  2022 onwards, Blindside Networks Inc
31
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 * @author     Laurent David  (laurent [at] call-learning [dt] fr)
33
 */
34
class text_with_copy_element extends MoodleQuickForm_text {
35
 
36
    /** @var string an element template. */
37
    public $_groupElementTemplate;
38
 
39
    /**
40
     * Accepts a renderer
41
     *
42
     * @param object $renderer An HTML_QuickForm_Renderer object
43
     * @param bool $required Whether an element is required
44
     * @param string $error An error message associated with an element
45
     * @return void
46
     */
47
    public function accept(&$renderer, $required = false, $error = null) {
48
        global $OUTPUT;
49
        $elementname = $this->getName();
50
        // Make sure the element has an id.
51
        $this->_generateId();
52
        $advanced = isset($renderer->_advancedElements[$elementname]);
53
        $elementcontext = $this->export_for_template($OUTPUT);
54
 
55
        $helpbutton = '';
56
        if (method_exists($this, 'getHelpButton')) {
57
            $helpbutton = $this->getHelpButton();
58
        }
59
        $label = $this->getLabel();
60
        $text = '';
61
        if (method_exists($this, 'getText')) {
62
            // There currently exists code that adds a form element with an empty label.
63
            // If this is the case then set the label to the description.
64
            if (empty($label)) {
65
                $label = $this->getText();
66
            } else {
67
                $text = $this->getText();
68
            }
69
        }
70
 
71
        $context = array(
72
                'element' => $elementcontext,
73
                'label' => $label,
74
                'text' => $text,
75
                'required' => $required,
76
                'advanced' => $advanced,
77
                'helpbutton' => $helpbutton,
78
                'error' => $error,
79
                'copylabel' => $this->_attributes['copylabel'] ?? get_string('copy', 'core_editor')
80
        );
81
        $html = $OUTPUT->render_from_template('mod_bigbluebuttonbn/element_text_with_copy', $context);
82
        if ($renderer->_inGroup) {
83
            $this->_groupElementTemplate = $html;
84
        }
85
        if (($renderer->_inGroup) && !empty($renderer->_groupElementTemplate)) {
86
            $renderer->_groupElementTemplate = $html;
87
        } else if (!isset($renderer->_templates[$elementname])) {
88
            $renderer->_templates[$elementname] = $html;
89
        }
90
 
91
        if (in_array($elementname, $renderer->_stopFieldsetElements) && $renderer->_fieldsetsOpen > 0) {
92
            $renderer->_html .= $renderer->_closeFieldsetTemplate;
93
            $renderer->_fieldsetsOpen--;
94
        }
95
        $renderer->_html .= $html;
96
    }
97
 
98
}