Navigation Menu

Skip to content

Commit

Permalink
MDL-63694 core_block: New block class method for external content
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jleyva authored and stronk7 committed Oct 25, 2018
1 parent da73189 commit 96d9a6e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
33 changes: 33 additions & 0 deletions blocks/moodleblock.class.php
Expand Up @@ -272,6 +272,39 @@ public function get_content_for_output($output) {
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.
*
Expand Down
4 changes: 4 additions & 0 deletions blocks/upgrade.txt
Expand Up @@ -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 ===

Expand Down

0 comments on commit 96d9a6e

Please sign in to comment.