diff --git a/lib/pagelib.php b/lib/pagelib.php index 99366fc3872..8378da823d4 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -1241,9 +1241,10 @@ class moodle_page { * This is normally used as the main heading at the top of the content. * * @param string $heading the main heading that should be displayed at the top of the
. + * @param bool $applyformatting apply format_string() - by default true. */ - public function set_heading($heading) { - $this->_heading = format_string($heading); + public function set_heading($heading, bool $applyformatting = true) { + $this->_heading = $applyformatting ? format_string($heading) : clean_text($heading); } /** diff --git a/lib/tests/moodle_page_test.php b/lib/tests/moodle_page_test.php index a801a623c99..8fa2d661c52 100644 --- a/lib/tests/moodle_page_test.php +++ b/lib/tests/moodle_page_test.php @@ -311,6 +311,14 @@ class core_moodle_page_testcase extends advanced_testcase { $this->testpage->set_heading('a heading'); // Validated. $this->assertSame('a heading', $this->testpage->heading); + + // By default formatting is applied and tags are removed. + $this->testpage->set_heading('a heading edit'); + $this->assertSame('a heading edit', $this->testpage->heading); + + // Without formatting the tags are preserved but cleaned. + $this->testpage->set_heading('a heading edit
', false); + $this->assertSame('a heading edit
', $this->testpage->heading); } public function test_set_title() {