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.
This commit is contained in:
Juan Leyva 2018-10-17 16:16:12 +02:00 committed by Eloy Lafuente (stronk7)
parent da73189b84
commit 96d9a6e430
2 changed files with 37 additions and 0 deletions

View File

@ -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.
*

View File

@ -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 ===