3 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
19 * Form for editing HTML block instances.
22 * @copyright 2009 Tim Hunt
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 * Form for editing HTML block instances.
29 * @copyright 2009 Tim Hunt
30 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32 class block_html_edit_form
extends block_edit_form
{
33 protected function specific_definition($mform) {
36 // Fields for editing HTML block title and contents.
37 $mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
39 $mform->addElement('text', 'config_title', get_string('configtitle', 'block_html'));
40 $mform->setType('config_title', PARAM_TEXT
);
42 $editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES
, 'noclean'=>true, 'context'=>$this->block
->context
);
43 $mform->addElement('editor', 'config_text', get_string('configcontent', 'block_html'), null, $editoroptions);
44 $mform->addRule('config_text', null, 'required', null, 'client');
45 $mform->setType('config_text', PARAM_RAW
); // XSS is prevented when printing the block contents and serving files
47 if (!empty($CFG->block_html_allowcssclasses
)) {
48 $mform->addElement('text', 'config_classes', get_string('configclasses', 'block_html'));
49 $mform->setType('config_classes', PARAM_TEXT
);
50 $mform->addHelpButton('config_classes', 'configclasses', 'block_html');
54 function set_data($defaults) {
55 if (!empty($this->block
->config
) && is_object($this->block
->config
)) {
56 $text = $this->block
->config
->text
;
57 $draftid_editor = file_get_submitted_draft_itemid('config_text');
63 $defaults->config_text
['text'] = file_prepare_draft_area($draftid_editor, $this->block
->context
->id
, 'block_html', 'content', 0, array('subdirs'=>true), $currenttext);
64 $defaults->config_text
['itemid'] = $draftid_editor;
65 $defaults->config_text
['format'] = $this->block
->config
->format
;
70 if (!$this->block
->user_can_edit() && !empty($this->block
->config
->title
)) {
71 // If a title has been set but the user cannot edit it format it nicely
72 $title = $this->block
->config
->title
;
73 $defaults->config_title
= format_string($title, true, $this->page
->context
);
74 // Remove the title from the config so that parent::set_data doesn't set it.
75 unset($this->block
->config
->title
);
78 // have to delete text here, otherwise parent::set_data will empty content
80 unset($this->block
->config
->text
);
81 parent
::set_data($defaults);
83 if (!isset($this->block
->config
)) {
84 $this->block
->config
= new stdClass();
86 $this->block
->config
->text
= $text;
88 // Reset the preserved title
89 $this->block
->config
->title
= $title;