MDL-65788 tool_policy: Prevent two modals rendering for guests.
[moodle.git] / blocks / html / edit_form.php
CommitLineData
1d13c75c 1<?php
4ca6cfbf
PS
2// This file is part of Moodle - http://moodle.org/
3//
1d13c75c 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.
4ca6cfbf 13//
1d13c75c 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/**
18 * Form for editing HTML block instances.
19 *
64f93798 20 * @package block_html
1d13c75c 21 * @copyright 2009 Tim Hunt
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25/**
26 * Form for editing HTML block instances.
27 *
28 * @copyright 2009 Tim Hunt
29 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 */
31class block_html_edit_form extends block_edit_form {
32 protected function specific_definition($mform) {
055cc835
AB
33 global $CFG;
34
a60bdd8c 35 // Fields for editing HTML block title and contents.
1d13c75c 36 $mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
37
38 $mform->addElement('text', 'config_title', get_string('configtitle', 'block_html'));
071e68f9 39 $mform->setType('config_title', PARAM_TEXT);
1d13c75c 40
d449b246 41 $editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$this->block->context);
94ee9ae0 42 $mform->addElement('editor', 'config_text', get_string('configcontent', 'block_html'), null, $editoroptions);
2ee40a70 43 $mform->addRule('config_text', null, 'required', null, 'client');
d449b246 44 $mform->setType('config_text', PARAM_RAW); // XSS is prevented when printing the block contents and serving files
14bcde67 45
055cc835
AB
46 if (!empty($CFG->block_html_allowcssclasses)) {
47 $mform->addElement('text', 'config_classes', get_string('configclasses', 'block_html'));
48 $mform->setType('config_classes', PARAM_TEXT);
49 $mform->addHelpButton('config_classes', 'configclasses', 'block_html');
50 }
1d13c75c 51 }
41976db3
DC
52
53 function set_data($defaults) {
b1384289
DC
54 if (!empty($this->block->config) && is_object($this->block->config)) {
55 $text = $this->block->config->text;
56 $draftid_editor = file_get_submitted_draft_itemid('config_text');
57 if (empty($text)) {
ce162914
DC
58 $currenttext = '';
59 } else {
b1384289 60 $currenttext = $text;
ce162914 61 }
b1384289
DC
62 $defaults->config_text['text'] = file_prepare_draft_area($draftid_editor, $this->block->context->id, 'block_html', 'content', 0, array('subdirs'=>true), $currenttext);
63 $defaults->config_text['itemid'] = $draftid_editor;
64 $defaults->config_text['format'] = $this->block->config->format;
65 } else {
66 $text = '';
00ab45e7 67 }
34856876
SH
68
69 if (!$this->block->user_can_edit() && !empty($this->block->config->title)) {
70 // If a title has been set but the user cannot edit it format it nicely
71 $title = $this->block->config->title;
72 $defaults->config_title = format_string($title, true, $this->page->context);
73 // Remove the title from the config so that parent::set_data doesn't set it.
74 unset($this->block->config->title);
75 }
76
b1384289
DC
77 // have to delete text here, otherwise parent::set_data will empty content
78 // of editor
79 unset($this->block->config->text);
41976db3 80 parent::set_data($defaults);
b1384289 81 // restore $text
b85b25eb
PS
82 if (!isset($this->block->config)) {
83 $this->block->config = new stdClass();
84 }
b1384289 85 $this->block->config->text = $text;
34856876
SH
86 if (isset($title)) {
87 // Reset the preserved title
88 $this->block->config->title = $title;
89 }
41976db3 90 }
94ee9ae0 91}