Merge branch 'MDL-29421-501' of https://github.com/paulholden/moodle into MOODLE_501_STABLE
This commit is contained in:
@@ -217,8 +217,6 @@ class course_edit_form extends moodleform {
|
||||
}
|
||||
|
||||
if (!empty($course->id) and !has_capability('moodle/course:changesummary', $coursecontext)) {
|
||||
// Remove the description header it does not contain anything any more.
|
||||
$mform->removeElement('descriptionhdr');
|
||||
$mform->hardFreeze($summaryfields);
|
||||
}
|
||||
|
||||
|
||||
@@ -177,9 +177,8 @@ class gradingform_rubric_editrubric extends moodleform {
|
||||
}
|
||||
|
||||
// freeze form elements and pass the values in hidden fields
|
||||
// TODO MDL-29421 description_editor does not freeze the normal way, uncomment below when fixed
|
||||
$form = $this->_form;
|
||||
foreach (array('rubric', 'name'/*, 'description_editor'*/) as $fieldname) {
|
||||
foreach (['rubric', 'name', 'description_editor'] as $fieldname) {
|
||||
$el =& $form->getElement($fieldname);
|
||||
$el->freeze();
|
||||
$el->setPersistantFreeze(true);
|
||||
|
||||
@@ -41,7 +41,6 @@ require_once('templatable_form_element.php');
|
||||
* @category form
|
||||
* @copyright 2009 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @todo MDL-29421 element Freezing
|
||||
* @todo MDL-29426 ajax format conversion
|
||||
*/
|
||||
class MoodleQuickForm_editor extends HTML_QuickForm_element implements templatable {
|
||||
@@ -495,13 +494,51 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element implements templatab
|
||||
return $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by getFrozenHtml() to pass the element's value if _persistantFreeze is on
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function _getPersistantData() {
|
||||
if (!$this->_persistantFreeze) {
|
||||
return '';
|
||||
} else {
|
||||
$id = $this->getAttribute('id');
|
||||
if (isset($id)) {
|
||||
// Id of persistant input is different then the actual input.
|
||||
$id = ['id' => $id . '_persistant'];
|
||||
} else {
|
||||
$id = [];
|
||||
}
|
||||
|
||||
$str = '';
|
||||
foreach ($this->getValue() as $key => $value) {
|
||||
$str .= html_writer::empty_tag('input', [
|
||||
'type' => 'hidden',
|
||||
'name' => $this->getName() . "[{$key}]",
|
||||
'value' => $value,
|
||||
] + $id);
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the formatted value. The return from parent class is not acceptable.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFrozenHtml(): string {
|
||||
return format_text($this->get_text(), $this->getFormat()) . $this->_getPersistantData();
|
||||
global $CFG;
|
||||
|
||||
['text' => $text, 'format' => $format] = $this->getValue();
|
||||
|
||||
// In post-formatted content, draftfiles are never expected to exist. However, in this case we do need to show
|
||||
// embedded draft files, because they are expected to exist in the editor element.
|
||||
$content = format_text($text, $format, ['context' => $this->_options['context'], 'overflowdiv' => true]);
|
||||
$content = str_replace("\"$CFG->wwwroot/brokenfile.php#", "\"$CFG->wwwroot/draftfile.php", $content);
|
||||
|
||||
return $content . $this->_getPersistantData();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace core_form;
|
||||
|
||||
use advanced_testcase;
|
||||
use MoodleQuickForm_editor;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once("{$CFG->libdir}/form/editor.php");
|
||||
|
||||
/**
|
||||
* Tests for the editor form element
|
||||
*
|
||||
* @package core_form
|
||||
* @covers \MoodleQuickForm_editor
|
||||
* @copyright 2026 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
final class editor_test extends advanced_testcase {
|
||||
/**
|
||||
* Test retrieving frozen HTML
|
||||
*/
|
||||
public function test_get_frozen_html(): void {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
// Ensure "URL" filter is active.
|
||||
filter_set_global_state('urltolink', TEXTFILTER_ON);
|
||||
|
||||
$element = new MoodleQuickForm_editor('description_editor', 'Description');
|
||||
$element->setValue(['text' => 'http://example.com', 'format' => FORMAT_HTML]);
|
||||
|
||||
$this->assertStringContainsString(
|
||||
'<a href="http://example.com" class="_blanktarget">http://example.com</a>',
|
||||
$element->getFrozenHtml(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user