Commit 96d9a6e4 authored by Juan Leyva's avatar Juan Leyva Committed by Eloy Lafuente
Browse files

MDL-63694 core_block: New block class method for external content

New method added block_base::get_content_for_external().
It will return all the block contents rendered for external functions.
If your block is returning formatted content or provide files for download,
you should override this method to use the external_format_text,
external_format_string functions for formatting or
external_util::get_area_files for files.
See block_html as example.
parent da73189b
......@@ -272,6 +272,39 @@ class block_base {
return $bc;
}
/**
* Return an object containing all the block content to be returned by external functions.
*
* If your block is returning formatted content or provide files for download, you should override this method to use the
* external_format_text, external_format_string functions for formatting or external_util::get_area_files for files.
*
* @param core_renderer $output the rendered used for output
* @return stdClass object containing the block title, central content, footer and linked files (if any).
* @since Moodle 3.6
*/
public function get_content_for_external($output) {
$bc = new stdClass;
$bc->title = null;
$bc->content = null;
$bc->contentformat = FORMAT_HTML;
$bc->footer = null;
$bc->files = [];
if ($this->instance->visible) {
$bc->content = $this->formatted_contents($output);
if (!empty($this->content->footer)) {
$bc->footer = $this->content->footer;
}
}
if (!$this->hide_header()) {
$bc->title = $this->title;
}
return $bc;
}
/**
* Convert the contents of the block to HTML.
*
......
......@@ -5,6 +5,10 @@ information provided here is intended especially for developers.
* The timeline view from block_myoverview has been split out into block_timeline.
* External function core_blocks::get_course_blocks now returns the block visible status and weight for ordering.
* New method added block_base::get_content_for_external(). It will return all the block contents rendered for external functions.
If your block is returning formatted content or provide files for download, you should override this method to use the
external_format_text, external_format_string functions for formatting or external_util::get_area_files for files.
See block_html as example.
=== 3.4 ===
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment