block
abstract class block extends abstract_block
Public SDK Block.
Extend this class to publish Moodle blocks that delegate rendering and business logic to your extension services instead of Moodle globals.
Constants
| TEMPLATE |
The template associated with this block. This constant holds the name the template used to render the output of the block. If empty, a default template might be used. Override in child classes. |
Properties
| protected string | $title | from abstract_block | |
| protected array<string,mixed> | $content | from abstract_block | |
| protected array<string,string> | $attributes | from abstract_block |
Methods
Sets an HTML attribute for the block wrapper.
Renders the widget using the specified template and processed content.
Gets the attributes string safely using Moodle's html_writer.
Details
in
abstract_block at line 66
abstract void
set_title()
Logic to determine and set the block title.
Called automatically by get_title() if needed.
in
abstract_block at line 73
string
get_title()
Get the block title, lazily loading it if empty.
in
abstract_block at line 87
abstract array
process_content()
Main logic to fetch data for the block.
in
abstract_block at line 97
array
get_content()
Retrieves all the content of the block with memoization.
Using a boolean flag ($processed) is safer than checking for empty array, as the content might legitimately be empty after processing.
in
abstract_block at line 113
void
set_attribute(string $key, string $value)
Sets an HTML attribute for the block wrapper.
in
abstract_block at line 123
string
render()
Renders the widget using the specified template and processed content.
in
abstract_block at line 153
protected string
get_attributes()
Gets the attributes string safely using Moodle's html_writer.
This handles escaping and boolean attributes correctly.