MDL-23916 JS now allowed on private /my/ pages again
[moodle.git] / blocks / html / edit_form.php
CommitLineData
1d13c75c 1<?php
2
4ca6cfbf
PS
3// This file is part of Moodle - http://moodle.org/
4//
1d13c75c 5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
4ca6cfbf 14//
1d13c75c 15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * Form for editing HTML block instances.
20 *
64f93798 21 * @package block_html
1d13c75c 22 * @copyright 2009 Tim Hunt
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26/**
27 * Form for editing HTML block instances.
28 *
29 * @copyright 2009 Tim Hunt
30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31 */
32class block_html_edit_form extends block_edit_form {
33 protected function specific_definition($mform) {
a60bdd8c 34 // Fields for editing HTML block title and contents.
1d13c75c 35 $mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
36
37 $mform->addElement('text', 'config_title', get_string('configtitle', 'block_html'));
a60bdd8c 38 $mform->setType('config_title', PARAM_MULTILANG);
1d13c75c 39
d449b246 40 $editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$this->block->context);
94ee9ae0 41 $mform->addElement('editor', 'config_text', get_string('configcontent', 'block_html'), null, $editoroptions);
d449b246 42 $mform->setType('config_text', PARAM_RAW); // XSS is prevented when printing the block contents and serving files
1d13c75c 43 }
41976db3
DC
44
45 function set_data($defaults) {
b1384289
DC
46 if (!empty($this->block->config) && is_object($this->block->config)) {
47 $text = $this->block->config->text;
48 $draftid_editor = file_get_submitted_draft_itemid('config_text');
49 if (empty($text)) {
ce162914
DC
50 $currenttext = '';
51 } else {
b1384289 52 $currenttext = $text;
ce162914 53 }
b1384289
DC
54 $defaults->config_text['text'] = file_prepare_draft_area($draftid_editor, $this->block->context->id, 'block_html', 'content', 0, array('subdirs'=>true), $currenttext);
55 $defaults->config_text['itemid'] = $draftid_editor;
56 $defaults->config_text['format'] = $this->block->config->format;
57 } else {
58 $text = '';
00ab45e7 59 }
b1384289
DC
60 // have to delete text here, otherwise parent::set_data will empty content
61 // of editor
62 unset($this->block->config->text);
41976db3 63 parent::set_data($defaults);
b1384289
DC
64 // restore $text
65 $this->block->config->text = $text;
41976db3 66 }
94ee9ae0 67}