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

void
set_title()

Logic to determine and set the block title.

string
get_title()

Get the block title, lazily loading it if empty.

array
process_content()

Main logic to fetch data for the block.

array
get_content()

Retrieves all the content of the block with memoization.

void
set_attribute(string $key, string $value)

Sets an HTML attribute for the block wrapper.

string
render()

Renders the widget using the specified template and processed content.

string
get_attributes()

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.

Return Value

void

in abstract_block at line 73
string get_title()

Get the block title, lazily loading it if empty.

Return Value

string

in abstract_block at line 87
abstract array process_content()

Main logic to fetch data for the block.

Return Value

array

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.

Return Value

array

in abstract_block at line 113
void set_attribute(string $key, string $value)

Sets an HTML attribute for the block wrapper.

Parameters

string $key
string $value

Return Value

void

in abstract_block at line 123
string render()

Renders the widget using the specified template and processed content.

Return Value

string

Rendered HTML fragment

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.

Return Value

string

the attributes formatted for HTML