Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
block_navigation Class Reference

The global navigation tree block class. More...

Inheritance diagram for block_navigation:
block_base

Public Member Functions

 _load_instance ($instance, $page)
 Set up a particular instance of this class given data from the block_insances table and the current page.
 
 _self_test ()
 Tests if this block has been implemented correctly.
 
 applicable_formats ()
 Set the applicable formats for this block to all.
 
 before_delete ()
 Function that can be overridden to do extra cleanup before the database tables are deleted.
 
 can_block_be_added (moodle_page $page)
 This method can be overriden to add some extra checks to decide whether the block can be added or not to a page.
 
 config_save ($data)
 Default behavior: save all variables as $CFG properties You don't need to override this if you 're satisfied with the above.
 
 get_aria_role ()
 Returns the role that best describes the navigation block... 'navigation'.
 
 get_config_for_external ()
 Return the plugin config settings for external functions.
 
 get_content ()
 Gets the content for this block by grabbing it from $this->page.
 
 get_content_for_external ($output)
 Return an object containing all the block content to be returned by external functions.
 
 get_content_for_output ($output)
 Return a block_contents object representing the full contents of this block.
 
 get_content_type ()
 Returns the class $content_type var value.
 
 get_required_javascript ()
 Gets Javascript that may be required for navigation.
 
 get_title ()
 Returns the class $title var value.
 
 has_config ()
 Subclasses should override this and return true if the subclass block has a settings.php file.
 
 hide_header ()
 Default return is false - header will be shown.
 
 html_attributes ()
 Returns the attributes to set for this block.
 
 init ()
 Set the initial properties for the block.
 
 instance_allow_config ()
 Allow the user to configure a block instance.
 
 instance_allow_multiple ()
 All multiple instances of this block.
 
 instance_can_be_collapsed ()
 If overridden and set to false by the block it will not be collapsible.
 
 instance_can_be_docked ()
 Find out if an instance can be docked.
 
 instance_can_be_edited ()
 If overridden and set to false by the block it will not be editable.
 
 instance_can_be_hidden ()
 The navigation block cannot be hidden by default as it is integral to the navigation of Moodle.
 
 instance_config_commit ($nolongerused=false)
 Replace the instance's configuration data with those currently in $this->config;.
 
 instance_config_save ($data, $nolongerused=false)
 Serialize and store config data.
 
 instance_copy ($fromid)
 Copy any block-specific data when copying to a new block instance.
 
 instance_create ()
 Do any additional initialization you may need at the time a new block instance is created.
 
 instance_delete ()
 Delete everything related to this instance if you have been using persistent storage other than the configdata field.
 
 is_empty ()
 Returns true or false, depending on whether this block has any content to display and whether the user has permission to view the block.
 
 name ()
 Returns the block name, as present in the class name, the database, the block directory, etc etc.
 
 refresh_content ()
 First sets the current value of $this->content to NULL then calls the block's get_content() function to set its value back.
 
 specialization ()
 This function is called on your subclass right after an instance is loaded Use this function to act on instance data just after it's loaded and before anything else is done For instance: if your block will have different title's depending on location (site, course, blog, etc)
 
 trim (navigation_node $node, $mode=1, $long=50, $short=25, $recurse=true)
 Trims the text and shorttext properties of this node and optionally all of its children.
 
 user_can_addto ($page)
 Allows the block class to have a say in the user's ability to create new instances of this block.
 
 user_can_edit ()
 Allows the block class to have a say in the user's ability to edit (i.e., configure) blocks of this type.
 

Static Public Member Functions

static comment_add (&$comments, $options)
 
static comment_display ($comments, $options)
 
static comment_permissions ($options)
 
static comment_template ($options)
 @callback callback functions for comments api
 
static comment_url ($options)
 
static get_extra_capabilities ()
 

Public Attributes

string $arialabel = NULL
 The name of the block to be displayed in the block title area if the title is empty.
 
string $blockname = null
 The name of the block.
 
stdClass $config = NULL
 An object containing the instance configuration information for the current instance of this block.
 
stdClass $content = NULL
 An object to contain the information to be displayed in the block.
 
int $content_type = BLOCK_TYPE_TEXT
 The type of content that this block creates.
 
context $context = NULL
 This blocks's context.
 
int $cron = NULL
 How often the cronjob should run, 0 if not at all.
 
stdClass $instance = NULL
 The initialized instance of this block object.
 
moodle_page $page = NULL
 The page that this block is appearing on.
 
string $str
 Internal var for storing/caching translated strings $str.
 
string $title = NULL
 The title of the block to be displayed in the block title area.
 
int const TRIM_CENTER = 3
 Trim characters from the center.
 
int const TRIM_LEFT = 2
 Trim characters from the left.
 
int const TRIM_RIGHT = 1
 Trim characters from the right.
 

Static Public Attributes

static int $navcount
 This allows for multiple navigation trees.
 

Protected Member Functions

 formatted_contents ($output)
 Convert the contents of the block to HTML.
 
 get_navigation ()
 Returns the navigation.
 
 trim_center ($string, $length)
 Truncate a string in the center.
 
 trim_left ($string, $length)
 Truncate a string from the left.
 
 trim_right ($string, $length)
 Truncate a string from the right.
 

Protected Attributes

bool $contentgenerated = false
 A switch to indicate whether content has been generated or not.
 
bool null $docked = null
 variable for checking if the block is docked
 

Detailed Description

The global navigation tree block class.

Used to produce the global navigation block new to Moodle 2.0

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ _load_instance()

block_base::_load_instance ( $instance,
$page )
inherited

Set up a particular instance of this class given data from the block_insances table and the current page.

(See block_manager::load_blocks().)

Parameters
stdClass$instancedata from block_insances, block_positions, etc.
moodle_page$pagethe page this block is on.

◆ _self_test()

block_base::_self_test ( )
inherited

Tests if this block has been implemented correctly.

Also, $errors isn't used right now

Return values
boolean

◆ applicable_formats()

block_navigation::applicable_formats ( )

Set the applicable formats for this block to all.

Return values
array

Reimplemented from block_base.

◆ before_delete()

block_base::before_delete ( )
inherited

Function that can be overridden to do extra cleanup before the database tables are deleted.

(Called once per block, not per instance!)

Reimplemented in block_myprofile.

◆ can_block_be_added()

block_base::can_block_be_added ( moodle_page $page)
inherited

This method can be overriden to add some extra checks to decide whether the block can be added or not to a page.

It doesn't need to do the standard capability checks as they will be performed by has_add_block_capability(). This method is user agnostic. If you want to check if a user can add a block or not, you should use user_can_addto().

Parameters
moodle_page$pageThe page where this block will be added.
Return values
boolWhether the block can be added or not to the given page.

Reimplemented in block_accessreview, block_badges, block_blog_menu, block_blog_recent, block_blog_tags, block_comments, block_completionstatus, block_globalsearch, block_glossary_random, block_lp, block_mnet_hosts, and block_tags.

◆ config_save()

block_base::config_save ( $data)
inherited

Default behavior: save all variables as $CFG properties You don't need to override this if you 're satisfied with the above.

Deprecated
since Moodle 2.9 MDL-49385 - Please use Admin Settings functionality to save block configuration.

◆ formatted_contents()

block_base::formatted_contents ( $output)
protectedinherited

Convert the contents of the block to HTML.

This is used by block base classes like block_list to convert the structured $this->content->list and $this->content->icons arrays to HTML. So, in most blocks, you probaby want to override the get_contents() method, which generates that structured representation of the contents.

Parameters
$outputThe core_renderer to use when generating the output.
Return values
stringthe HTML that should appearn in the body of the block.
Since
Moodle 2.0.

Reimplemented in block_list, and block_tree.

◆ get_aria_role()

block_navigation::get_aria_role ( )

Returns the role that best describes the navigation block... 'navigation'.

Return values
string'navigation'

Reimplemented from block_base.

◆ get_config_for_external()

block_navigation::get_config_for_external ( )

Return the plugin config settings for external functions.

Return values
stdClassthe configs for both the block instance and plugin
Since
Moodle 3.8

Reimplemented from block_base.

◆ get_content()

block_navigation::get_content ( )

Gets the content for this block by grabbing it from $this->page.

Return values
object\$this-,>content

Reimplemented from block_base.

◆ get_content_for_external()

block_base::get_content_for_external ( $output)
inherited

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 core_external\util\format_text, core_external\utilformat_string functions for formatting or external_util\get_area_files for files.

Parameters
core_renderer$outputthe rendered used for output
Return values
stdClassobject containing the block title, central content, footer and linked files (if any).
Since
Moodle 3.6

Reimplemented in block_html.

◆ get_content_for_output()

block_base::get_content_for_output ( $output)
inherited

Return a block_contents object representing the full contents of this block.

This internally calls ->get_content(), and then adds the editing controls etc.

You probably should not override this method, but instead override html_attributes(), formatted_contents() or get_content(), hide_header(), (get_edit_controls), etc.

Return values
block_contentsa representation of the block, for rendering.
Since
Moodle 2.0.

◆ get_content_type()

block_base::get_content_type ( )
inherited

Returns the class $content_type var value.

Intentionally doesn't check if content_type is set. This is already done in _self_test()

Return values
string\$this-,>content_type

◆ get_navigation()

block_navigation::get_navigation ( )
protected

Returns the navigation.

Return values
navigation_nodeThe navigation object to display

◆ get_required_javascript()

block_navigation::get_required_javascript ( )

Gets Javascript that may be required for navigation.

Reimplemented from block_base.

◆ get_title()

block_base::get_title ( )
inherited

Returns the class $title var value.

Intentionally doesn't check if a title is set. This is already done in _self_test()

Return values
string\$this-,>title

◆ has_config()

block_base::has_config ( )
inherited

◆ hide_header()

block_base::hide_header ( )
inherited

Default return is false - header will be shown.

Return values
boolean

Reimplemented in block_course_summary, and block_myoverview.

◆ html_attributes()

block_navigation::html_attributes ( )

Returns the attributes to set for this block.

This function returns an array of HTML attributes for this block including the defaults. block_tree::html_attributes() is used to get the default arguments and then we check whether the user has enabled hover expansion and add the appropriate hover class if it has.

Return values
arrayAn array of HTML attributes

Reimplemented from block_base.

◆ instance_allow_config()

block_navigation::instance_allow_config ( )

Allow the user to configure a block instance.

Return values
boolReturns true

Reimplemented from block_base.

◆ instance_allow_multiple()

block_navigation::instance_allow_multiple ( )

All multiple instances of this block.

Return values
boolReturns false

Reimplemented from block_base.

◆ instance_can_be_collapsed()

block_base::instance_can_be_collapsed ( )
inherited

If overridden and set to false by the block it will not be collapsible.

Return values
bool

◆ instance_can_be_docked()

block_navigation::instance_can_be_docked ( )

Find out if an instance can be docked.

Return values
booltrue or false depending on whether the instance can be docked or not.

Reimplemented from block_base.

◆ instance_can_be_edited()

block_base::instance_can_be_edited ( )
inherited

If overridden and set to false by the block it will not be editable.

Return values
bool

Reimplemented in block_myoverview.

◆ instance_can_be_hidden()

block_navigation::instance_can_be_hidden ( )

The navigation block cannot be hidden by default as it is integral to the navigation of Moodle.

Return values
false

Reimplemented from block_base.

◆ instance_config_commit()

block_base::instance_config_commit ( $nolongerused = false)
inherited

Replace the instance's configuration data with those currently in $this->config;.

Reimplemented in block_glossary_random.

◆ instance_config_save()

block_base::instance_config_save ( $data,
$nolongerused = false )
inherited

Serialize and store config data.

Reimplemented in block_activity_results, and block_html.

◆ instance_copy()

block_base::instance_copy ( $fromid)
inherited

Copy any block-specific data when copying to a new block instance.

Parameters
int$fromidthe id number of the block instance to copy from
Return values
boolean

Reimplemented in block_html.

◆ instance_create()

block_base::instance_create ( )
inherited

Do any additional initialization you may need at the time a new block instance is created.

Return values
boolean

◆ instance_delete()

block_base::instance_delete ( )
inherited

Delete everything related to this instance if you have been using persistent storage other than the configdata field.

Return values
boolean

Reimplemented in block_html.

◆ is_empty()

block_base::is_empty ( )
inherited

Returns true or false, depending on whether this block has any content to display and whether the user has permission to view the block.

Return values
boolean

Reimplemented in block_list.

◆ name()

block_base::name ( )
inherited

Returns the block name, as present in the class name, the database, the block directory, etc etc.

Return values
string

◆ refresh_content()

block_base::refresh_content ( )
inherited

First sets the current value of $this->content to NULL then calls the block's get_content() function to set its value back.

Return values
stdObject

◆ specialization()

block_base::specialization ( )
inherited

This function is called on your subclass right after an instance is loaded Use this function to act on instance data just after it's loaded and before anything else is done For instance: if your block will have different title's depending on location (site, course, blog, etc)

Reimplemented in block_badges, block_blog_tags, block_comments, block_course_summary, block_glossary_random, block_html, block_mentees, block_myprofile, block_private_files, block_rss_client, block_tag_flickr, block_tag_youtube, and block_tags.

◆ trim()

block_navigation::trim ( navigation_node $node,
$mode = 1,
$long = 50,
$short = 25,
$recurse = true )

Trims the text and shorttext properties of this node and optionally all of its children.

Parameters
navigation_node$node
int$modeOne of navigation_node\TRIM_*
int$longThe length to trim text to
int$shortThe length to trim shorttext to
bool$recurseRecurse all children

◆ trim_center()

block_navigation::trim_center ( $string,
$length )
protected

Truncate a string in the center.

Parameters
string$stringThe string to truncate
int$lengthThe length to truncate to
Return values
stringThe truncated string

◆ trim_left()

block_navigation::trim_left ( $string,
$length )
protected

Truncate a string from the left.

Parameters
string$stringThe string to truncate
int$lengthThe length to truncate to
Return values
stringThe truncated string

◆ trim_right()

block_navigation::trim_right ( $string,
$length )
protected

Truncate a string from the right.

Parameters
string$stringThe string to truncate
int$lengthThe length to truncate to
Return values
stringThe truncated string

◆ user_can_addto()

block_base::user_can_addto ( $page)
inherited

Allows the block class to have a say in the user's ability to create new instances of this block.

The framework has first say in whether this will be allowed (e.g., no adding allowed unless in edit mode) but if the framework does allow it, the block can still decide to refuse. This function has access to the complete page object, the creation related to which is being determined.

Parameters
moodle_page$page
Return values
boolean

◆ user_can_edit()

block_base::user_can_edit ( )
inherited

Allows the block class to have a say in the user's ability to edit (i.e., configure) blocks of this type.

The framework has first say in whether this will be allowed (e.g., no editing allowed unless in edit mode) but if the framework does allow it, the block can still decide to refuse.

Return values
boolean

Member Data Documentation

◆ $arialabel

string block_base::$arialabel = NULL
inherited

The name of the block to be displayed in the block title area if the title is empty.

arialabel

◆ $config

stdClass block_base::$config = NULL
inherited

An object containing the instance configuration information for the current instance of this block.

$config

◆ $content

stdClass block_base::$content = NULL
inherited

An object to contain the information to be displayed in the block.

$content

◆ $content_type

int block_base::$content_type = BLOCK_TYPE_TEXT
inherited

The type of content that this block creates.

Currently support options - BLOCK_TYPE_LIST, BLOCK_TYPE_TEXT $content_type

◆ $cron

int block_base::$cron = NULL
inherited

How often the cronjob should run, 0 if not at all.

$cron

◆ $instance

stdClass block_base::$instance = NULL
inherited

The initialized instance of this block object.

$instance

◆ $title

string block_base::$title = NULL
inherited

The title of the block to be displayed in the block title area.

$title


The documentation for this class was generated from the following file: