Moodle APIs
3.8
Moodle 3.8.6 (Build: 20201109)
|
This class keeps track of the block that should appear on a moodle_page. More...
Public Member Functions | |
__construct ($page) | |
Constructor ================================================================. More... | |
add_block ($blockname, $region, $weight, $showinsubcontexts, $pagetypepattern=NULL, $subpagepattern=NULL) | |
Add a block to the current page, or related pages. More... | |
add_block_at_end_of_default_region ($blockname) | |
add_blocks ($blocks, $pagetypepattern=NULL, $subpagepattern=NULL, $showinsubcontexts=false, $weight=0) | |
Convenience method, calls add_block repeatedly for all the blocks in $blocks. More... | |
add_custom_regions_for_pagetype ($pagetype) | |
Finds custom block regions associated with a page type and registers them with this block manager. More... | |
add_fake_block ($bc, $region) | |
Add something that looks like a block, but which isn't an actual block_instance, to this page. More... | |
add_region ($region, $custom=true) | |
Setter methods =============================================================. More... | |
add_regions ($regions, $custom=true) | |
Add an array of regions. More... | |
create_all_block_instances () | |
Create all the block instances for all the blocks that were loaded by load_blocks. More... | |
edit_controls ($block) | |
Process actions from the URL ===============================================. More... | |
ensure_content_created ($region, $output) | |
Ensure that there is some content within the given region. More... | |
find_instance ($instanceid) | |
Find a given block by its instance id. More... | |
get_addable_blocks () | |
The list of block types that may be added to this page. More... | |
get_blocks_for_region ($region) | |
Get an array of all blocks within a given region. More... | |
get_content_for_all_regions ($output) | |
Returns an array of block content objects for all the existings regions. More... | |
get_content_for_region ($region, $output) | |
Returns an array of block content objects that exist in a region. More... | |
get_default_region () | |
Get the region name of the region blocks are added to by default. More... | |
get_installed_blocks () | |
Get an array of all of the installed blocks. More... | |
get_regions () | |
Getter methods =============================================================. More... | |
get_required_by_theme_block_types () | |
is_block_present ($blockname) | |
Given a block name, find out of any of them are currently present in the page. More... | |
is_known_block_type ($blockname, $includeinvisible=false) | |
Find out if a block type is known by the system. More... | |
is_known_region ($region) | |
Find out if a region exists on a page. More... | |
load_blocks ($includeinvisible=null) | |
Actions ====================================================================. More... | |
process_url_actions () | |
Process any block actions that were specified in the URL. More... | |
process_url_add () | |
Handle adding a block. More... | |
process_url_delete () | |
Handle deleting a block. More... | |
process_url_edit () | |
Handle showing/processing the submission from the block editing form. More... | |
process_url_move () | |
Handle showing/processing the submission from the block editing form. More... | |
process_url_show_hide () | |
Handle showing or hiding a block. More... | |
region_completely_docked ($region, $output) | |
Checks to see whether all of the blocks within the given region are docked. More... | |
region_has_content ($region, $output) | |
Determine whether a region contains anything. More... | |
region_uses_dock ($regions, $output) | |
Checks to see whether any of the blocks within the given regions are docked. More... | |
reposition_block ($blockinstanceid, $newregion, $newweight) | |
Move a block to a new position on this page. More... | |
set_default_region ($defaultregion) | |
Set the default region for new blocks on the page. More... | |
show_only_fake_blocks ($setting=true) | |
Turns the display of normal blocks either on or off. More... | |
Static Public Member Functions | |
static | get_undeletable_block_types () |
Get the list of "protected" blocks via admin block manager ui. More... | |
static | protect_block ($blockidorname) |
Make this block type undeletable and unaddable. More... | |
static | unprotect_block ($blockidorname) |
Make this block type deletable and addable. More... | |
Public Attributes | |
const | MAX_WEIGHT = 10 |
The UI normally only shows block weights between -MAX_WEIGHT and MAX_WEIGHT, although other weights are valid. | |
Protected Member Functions | |
add_block_required_by_theme ($blockname) | |
Add a block that is required by the current theme but has not been created yet. More... | |
check_is_loaded () | |
Check whether the page blocks have been loaded yet. More... | |
check_known_block_type ($blockname, $includeinvisible=false) | |
Check if a block type is known and usable. More... | |
check_not_yet_loaded () | |
Inner workings =============================================================. More... | |
check_region_is_known ($region) | |
Check if a region is known by its name. More... | |
create_block_contents ($instances, $output, $region) | |
Return an array of content objects from a set of block instances. More... | |
create_block_instances ($birecords) | |
Create a set of new block instance from a record array. More... | |
ensure_instances_exist ($region) | |
Ensure block instances exist for a given region. More... | |
get_move_target_url ($region, $weight) | |
Helper method used by get_content_for_region. More... | |
prepare_per_region_arrays () | |
Returns an array of region names as keys and nested arrays for values. More... | |
user_can_delete_block ($block) | |
Protected Attributes | |
array | $addableblocks = null |
blocks that this user can add to this page. More... | |
array | $allblocks = null |
will be $DB->get_records('blocks') | |
array | $birecordsbyregion = null |
Will be an array region-name => array(db rows loaded in load_blocks);. | |
array | $blockinstances = array() |
array region-name => array(block objects); populated as necessary by the ensure_instances_exist method. | |
string | $defaultregion = null |
the region where new blocks are added. | |
array | $extracontent = array() |
array region-name => array(block_contents objects) extra block-like things to be displayed in each region, before the real blocks. | |
$fakeblocksonly = false | |
Show only fake blocks. | |
integer null | $movingblock = null |
Used by the block move id, to track whether a block is currently being moved. More... | |
moodle_page | $page |
Field declarations =========================================================. More... | |
array | $regions = array() |
region name => 1. | |
array | $visibleblockcontent = array() |
array region-name => array(block_contents objects) what actually needs to be displayed in each region. | |
This class keeps track of the block that should appear on a moodle_page.
The page to work with as passed to the constructor.
block_manager::__construct | ( | $page | ) |
Constructor ================================================================.
Constructor.
object | $page | the moodle_page object object we are managing the blocks for, or a reasonable faxilimily. (See the comment at the top of this class and http://en.wikipedia.org/wiki/Duck_typing) |
block_manager::add_block | ( | $blockname, | |
$region, | |||
$weight, | |||
$showinsubcontexts, | |||
$pagetypepattern = NULL , |
|||
$subpagepattern = NULL |
|||
) |
Add a block to the current page, or related pages.
The block is added to context $this->page->contextid. If $pagetypepattern $subpagepattern
string | $blockname | The type of block to add. |
string | $region | the block region on this page to add the block to. |
integer | $weight | determines the order where this block appears in the region. |
boolean | $showinsubcontexts | whether this block appears in subcontexts, or just the current context. |
string | null | $pagetypepattern | which page types this block should appear on. Defaults to just the current page type. |
string | null | $subpagepattern | which subpage this block should appear on. NULL = any (the default), otherwise only the specified subpage. |
|
protected |
Add a block that is required by the current theme but has not been created yet.
This is a special type of block that only shows in themes that require it (by listing it in undeletable_block_types).
string | $blockname | the name of the block type. |
block_manager::add_blocks | ( | $blocks, | |
$pagetypepattern = NULL , |
|||
$subpagepattern = NULL , |
|||
$showinsubcontexts = false , |
|||
$weight = 0 |
|||
) |
Convenience method, calls add_block repeatedly for all the blocks in $blocks.
Optionally, a starting weight can be used to decide the starting point that blocks are added in the region, the weight is passed to add_block and incremented by the position of the block in the $blocks array
array | $blocks | array with array keys the region names, and values an array of block names. |
string | $pagetypepattern | optional. Passed to } * string $subpagepattern optional. Passed to add_block() |
boolean | $showinsubcontexts | optional. Passed to add_block() |
integer | $weight | optional. Determines the starting point that the blocks are added in the region. |
block_manager::add_custom_regions_for_pagetype | ( | $pagetype | ) |
Finds custom block regions associated with a page type and registers them with this block manager.
string | $pagetype |
block_manager::add_fake_block | ( | $bc, | |
$region | |||
) |
Add something that looks like a block, but which isn't an actual block_instance, to this page.
block_contents | $bc | the content of the block-like thing. |
string | $region | a block region that exists on this page. |
block_manager::add_region | ( | $region, | |
$custom = true |
|||
) |
Setter methods =============================================================.
Add a region to a page
string | $region | add a named region where blocks may appear on the current page. This is an internal name, like 'side-pre', not a string to display in the UI. |
bool | $custom | True if this is a custom block region, being added by the page rather than the theme layout. |
block_manager::add_regions | ( | $regions, | |
$custom = true |
|||
) |
Add an array of regions.
array | $regions | this utility method calls add_region for each array element. |
|
protected |
Check whether the page blocks have been loaded yet.
Nearly identical to the above function check_not_yet_loaded() except different message
void | Throws coding exception if already loaded |
|
protected |
Check if a block type is known and usable.
string | $blockname | The block type name to search for |
bool | $includeinvisible | Include disabled block types in the initial pass |
void | Coding Exception thrown if unknown or not enabled |
|
protected |
Inner workings =============================================================.
Check whether the page blocks have been loaded yet
void | Throws coding exception if already loaded |
|
protected |
Check if a region is known by its name.
string | $region |
void | Coding Exception thrown if the region is not known |
block_manager::create_all_block_instances | ( | ) |
Create all the block instances for all the blocks that were loaded by load_blocks.
This is used, for example, to ensure that all blocks get a chance to initialise themselves via the block_base::specialize() method, before any output is done.
It is also used to create any blocks that are "requiredbytheme" by the current theme. These blocks that are auto-created have requiredbytheme set on the block instance so they are only visible on themes that require them.
|
protected |
Return an array of content objects from a set of block instances.
array | $instances | An array of block instances |
renderer_base | The renderer to use. | |
string | $region | the region name. |
array | An array of block_content (and possibly block_move_target) objects. |
|
protected |
Create a set of new block instance from a record array.
array | $birecords | An array of block instance records |
array | An array of instantiated block_instance objects |
block_manager::edit_controls | ( | $block | ) |
Process actions from the URL ===============================================.
Get the appropriate list of editing icons for a block. This is used to set } in block_base::get_contents_for_output().
$output | The core_renderer to use when generating the output. (Need to get icon paths.) |
an | array in the format for block_contents::$controls |
block_manager::ensure_content_created | ( | $region, | |
$output | |||
) |
Ensure that there is some content within the given region.
string | $region | The name of the region to check |
|
protected |
Ensure block instances exist for a given region.
string | $region | Check for bi's with the instance with this name |
block_manager::find_instance | ( | $instanceid | ) |
block_manager::get_addable_blocks | ( | ) |
The list of block types that may be added to this page.
array | block name => record from block table. |
block_manager::get_blocks_for_region | ( | $region | ) |
Get an array of all blocks within a given region.
string | $region | a block region that exists on this page. |
array | of block instances. |
block_manager::get_content_for_all_regions | ( | $output | ) |
Returns an array of block content objects for all the existings regions.
renderer_base | $output | the rendered to use |
array | of block block_contents objects for all the blocks in all regions. |
block_manager::get_content_for_region | ( | $region, | |
$output | |||
) |
Returns an array of block content objects that exist in a region.
string | $region | a block region that exists on this page. |
array | of block block_contents objects for all the blocks in a region. |
block_manager::get_default_region | ( | ) |
Get the region name of the region blocks are added to by default.
string | the internal names of the region where new blocks are added by default, and where any blocks from an unrecognised region are shown. (Imagine that blocks were added with one theme selected, then you switched to a theme with different block positions.) |
block_manager::get_installed_blocks | ( | ) |
Get an array of all of the installed blocks.
array | contents of the block table. |
|
protected |
Helper method used by get_content_for_region.
string | $region | region name |
float | $weight | weight. May be fractional, since you may want to move a block between ones with weight 2 and 3, say ($weight would be 2.5). |
string | URL for moving block $this->movingblock to this position. |
block_manager::get_regions | ( | ) |
Getter methods =============================================================.
Get an array of all region names on this page where a block may appear
array | the internal names of the regions on this page where block may appear. |
block_manager::get_required_by_theme_block_types | ( | ) |
array | names of block types that must exist on every page with this theme. |
|
static |
Get the list of "protected" blocks via admin block manager ui.
array | names of block types that cannot be added or deleted. E.g. array('navigation','settings'). |
block_manager::is_block_present | ( | $blockname | ) |
Given a block name, find out of any of them are currently present in the page.
string | $blockname | - the basic name of a block (eg "navigation") |
boolean | - is there one of these blocks in the current page? |
block_manager::is_known_block_type | ( | $blockname, | |
$includeinvisible = false |
|||
) |
Find out if a block type is known by the system.
string | $blockname | the name of the type of block. |
boolean | $includeinvisible | if false (default) only check 'visible' blocks, that is, blocks enabled by the admin. |
boolean | true if this block in installed. |
block_manager::is_known_region | ( | $region | ) |
Find out if a region exists on a page.
string | $region | a region name |
boolean | true if this region exists on this page. |
block_manager::load_blocks | ( | $includeinvisible = null | ) |
Actions ====================================================================.
This method actually loads the blocks for our page from the database.
boolean | null | $includeinvisible | null (default) - load hidden blocks if $this->page->user_is_editing(); true - load hidden blocks. false - don't load hidden blocks. |
Reimplemented in my_syspage_block_manager.
|
protected |
Returns an array of region names as keys and nested arrays for values.
array | an array where the array keys are the region names, and the array values are empty arrays. |
block_manager::process_url_actions | ( | ) |
Process any block actions that were specified in the URL.
boolean | true if anything was done. False if not. |
block_manager::process_url_add | ( | ) |
Handle adding a block.
boolean | true if anything was done. False if not. |
block_manager::process_url_delete | ( | ) |
Handle deleting a block.
boolean | true if anything was done. False if not. |
block_manager::process_url_edit | ( | ) |
Handle showing/processing the submission from the block editing form.
boolean | true if the form was submitted and the new config saved. Does not return if the editing form was displayed. False otherwise. |
block_manager::process_url_move | ( | ) |
Handle showing/processing the submission from the block editing form.
boolean | true if the form was submitted and the new config saved. Does not return if the editing form was displayed. False otherwise. |
block_manager::process_url_show_hide | ( | ) |
Handle showing or hiding a block.
boolean | true if anything was done. False if not. |
|
static |
Make this block type undeletable and unaddable.
mixed | $blockidorname | string or int |
block_manager::region_completely_docked | ( | $region, | |
$output | |||
) |
Checks to see whether all of the blocks within the given region are docked.
string | $region |
bool | True if all of the blocks within that region are docked |
Return false as from MDL-64506
block_manager::region_has_content | ( | $region, | |
$output | |||
) |
Determine whether a region contains anything.
(Either any real blocks, or the add new block UI.)
(You may wonder why the $output parameter is required. Unfortunately, because of the way that blocks work, the only reliable way to find out if a block will be visible is to get the content for output, and to get the content, you need a renderer. Fortunately, this is not a performance problem, because we cache the output that is generated, and in almost every case where we call region_has_content, we are about to output the blocks anyway, so we are not doing wasted effort.)
string | $region | a block region that exists on this page. |
core_renderer | $output | a core_renderer. normally the global $OUTPUT. |
boolean | Whether there is anything in this region. |
block_manager::region_uses_dock | ( | $regions, | |
$output | |||
) |
Checks to see whether any of the blocks within the given regions are docked.
array | string | $regions | array of regions (or single region) |
bool | True if any of the blocks within that region are docked |
Return false as from MDL-64506
block_manager::reposition_block | ( | $blockinstanceid, | |
$newregion, | |||
$newweight | |||
) |
Move a block to a new position on this page.
If this block cannot appear on any other pages, then we change defaultposition/weight in the block_instances table. Otherwise we just set the position on this page.
$blockinstanceid | the block instance id. |
$newregion | the new region name. |
$newweight | the new weight. |
block_manager::set_default_region | ( | $defaultregion | ) |
Set the default region for new blocks on the page.
string | $defaultregion | the internal names of the region where new blocks should be added by default, and where any blocks from an unrecognised region are shown. |
block_manager::show_only_fake_blocks | ( | $setting = true | ) |
Turns the display of normal blocks either on or off.
bool | $setting |
|
static |
Make this block type deletable and addable.
mixed | $blockidorname | string or int |
|
protected |
block_base | $block | a block that appears on this page. |
boolean | boolean whether the currently logged in user is allowed to delete this block. |
|
protected |
blocks that this user can add to this page.
Will be a subset of $allblocks, but with array keys block->name. Access this via the get_addable_blocks() method to ensure it is lazy-loaded.
|
protected |
Used by the block move id, to track whether a block is currently being moved.
When you click on the move icon of a block, first the page needs to reload with extra UI for choosing a new position for a particular block. In that situation this field holds the id of the block being moved.
|
protected |
Field declarations =========================================================.
the moodle_page we are managing blocks for.