Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402]

Defines the base class form used by blocks/edit.php to edit block instance configuration. It works with the {@see block_edit_form} class, or rather the particular subclass defined by this block, to do the editing.

Copyright: 2009 Tim Hunt
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 485 lines (21 kb)
Included or required:0 times
Referenced: 4 times
Includes or requires: 0 files

Defines 1 class


Class: block_edit_form  - X-Ref

The base class form used by blocks/edit.php to edit block instance configuration.

__get(string $name)   X-Ref
Magic getter for backward compatibility

param: string $name
return: block_base|moodle_page

get_page()   X-Ref
Page where we are adding or editing the block

To access you can also use magic property $this->page

return: moodle_page

get_block()   X-Ref
Instance of the block that is being added or edited

To access you can also use magic property $this->block

If {{@see self::display_form_when_adding()}} returns true and the configuration
form is displayed when adding block, the $this->block->id will be null.

return: block_base

definition()   X-Ref
Form definition


is_editing_the_frontpage()   X-Ref
Returns true if the user is editing a frontpage.

return: bool

prepare_defaults(stdClass $defaults)   X-Ref
Prepare block configuration data and add default values when needed

param: stdClass $defaults
return: stdClass

set_data($defaults)   X-Ref
Load in existing data as form defaults

param: stdClass $defaults
return: void

specific_definition($mform)   X-Ref
Override this to create any form fields specific to this type of block.

param: \MoodleQuickForm $mform the form being built.

get_data()   X-Ref
Return submitted data if properly submitted or returns NULL if validation fails or
if there is no submitted data.

return: stdClass submitted data; NULL if not valid or not submitted or cancelled

get_context_for_dynamic_submission()   X-Ref
Returns context where this form is used

return: context

check_access_for_dynamic_submission()   X-Ref
Checks if current user has access to this form, otherwise throws exception


process_dynamic_submission()   X-Ref
Process the form submission, used if form was submitted via AJAX


set_data_for_dynamic_submission()   X-Ref
Load in existing data as form defaults


get_page_url_for_dynamic_submission()   X-Ref
Returns url to set in $PAGE->set_url() when form is being rendered or submitted via AJAX

return: moodle_url

display_form_when_adding()   X-Ref
Display the configuration form when block is being added to the page

By default when block is added to the page it is added with the default configuration.
Some block may require configuration, for example, "glossary random entry" block
needs a glossary to be selected, "RSS feed" block needs an RSS feed to be selected, etc.

Such blocks can override this function and return true. These blocks must
ensure that the function specific_definition() will work if there is no current block id.

return: bool