From a9732b8977a8c325a307a95112147dc7fbcb0b27 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Wed, 17 Oct 2018 16:20:52 +0200 Subject: [PATCH] MDL-63694 block_html: Implement get_content_for_external --- blocks/html/block_html.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/blocks/html/block_html.php b/blocks/html/block_html.php index 505ff270311d0..954a8099fb76e 100644 --- a/blocks/html/block_html.php +++ b/blocks/html/block_html.php @@ -86,6 +86,41 @@ function get_content() { return $this->content; } + public function get_content_for_external($output) { + global $CFG; + require_once($CFG->libdir . '/externallib.php'); + + $bc = new stdClass; + $bc->title = null; + $bc->content = ''; + $bc->contenformat = FORMAT_MOODLE; + $bc->footer = ''; + $bc->files = []; + + if (!$this->hide_header()) { + $bc->title = $this->title; + } + + if (isset($this->config->text)) { + $filteropt = new stdClass; + if ($this->content_is_trusted()) { + // Fancy html allowed only on course, category and system blocks. + $filteropt->noclean = true; + } + + $format = FORMAT_HTML; + // Check to see if the format has been properly set on the config. + if (isset($this->config->format)) { + $format = $this->config->format; + } + list($bc->content, $bc->contentformat) = + external_format_text($this->config->text, $format, $this->context, 'block_html', 'content', null, $filteropt); + $bc->files = external_util::get_area_files($this->context->id, 'block_html', 'content', false, false); + + } + return $bc; + } + /** * Serialize and store config data