MDL-28595 do not print continue link if install fails
[moodle.git] / blocks / html / edit_form.php
blob35d6e9425cd35da417cf23434c3dfad517655829
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
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.
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/>.
18 /**
19 * Form for editing HTML block instances.
21 * @package block_html
22 * @copyright 2009 Tim Hunt
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 /**
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) {
34 // Fields for editing HTML block title and contents.
35 $mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
37 $mform->addElement('text', 'config_title', get_string('configtitle', 'block_html'));
38 $mform->setType('config_title', PARAM_MULTILANG);
40 $editoroptions = array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$this->block->context);
41 $mform->addElement('editor', 'config_text', get_string('configcontent', 'block_html'), null, $editoroptions);
42 $mform->setType('config_text', PARAM_RAW); // XSS is prevented when printing the block contents and serving files
45 function set_data($defaults) {
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)) {
50 $currenttext = '';
51 } else {
52 $currenttext = $text;
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 = '';
61 if (!$this->block->user_can_edit() && !empty($this->block->config->title)) {
62 // If a title has been set but the user cannot edit it format it nicely
63 $title = $this->block->config->title;
64 $defaults->config_title = format_string($title, true, $this->page->context);
65 // Remove the title from the config so that parent::set_data doesn't set it.
66 unset($this->block->config->title);
69 // have to delete text here, otherwise parent::set_data will empty content
70 // of editor
71 unset($this->block->config->text);
72 parent::set_data($defaults);
73 // restore $text
74 $this->block->config->text = $text;
75 if (isset($title)) {
76 // Reset the preserved title
77 $this->block->config->title = $title;