Moodle APIs 4.3
Moodle 4.3.6 (Build: 20240812)
core\output\choicelist Class Reference

A generic user choice output class. More...

Inheritance diagram for core\output\choicelist:

Public Member Functions

 __construct (?string $description=null)
 Constructor.
 
 add_option (string $value, string $name, array $definition=[])
 Add option to the user choice.
 
 count_options ()
 Get the number of options added to the choice list.
 
 export_for_template (renderer_base $output)
 Export for template.
 
 get_description ()
 Get the choice description option.
 
 get_selected_value ()
 Get the selected option.
 
 get_template_name (renderer_base $renderer)
 Get the name of the template to use for this templatable.
 
 get_template_name (\renderer_base $renderer)
 Get the name of the template to use for this templatable.
 
 set_description (string $value)
 Set the general choice description option.
 
 set_option_disabled (string $value, bool $disabled)
 Set the option disabled.
 
 set_option_extras (string $value, array $extras)
 Set the option disabled.
 
 set_selected_value (string $value)
 Set the selected option.
 

Protected Attributes

string $description = null
 the choice description.
 
object[] $options = []
 The user choices.
 
string $selected = null
 the selected option.
 

Detailed Description

A generic user choice output class.

This class can be used as a generic user choice data structure for any dropdown, modal, or any other component that offers choices to the user.

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

Constructor & Destructor Documentation

◆ __construct()

core\output\choicelist::__construct ( ?string $description = null)

Constructor.

Parameters
string$descriptionthe choice description.

Member Function Documentation

◆ add_option()

core\output\choicelist::add_option ( string $value,
string $name,
array $definition = [] )

Add option to the user choice.

The definition object could contain the following keys:

  • string description: the description of the option.
  • moodle_url url: the URL to link to.
  • pix_icon icon: the icon to display.
  • bool disabled: whether the option is disabled.
  • bool selected: whether the option is selected.
  • array extras: an array of HTML attributes to add to the option (attribute => value).
Parameters
string$value
string$name
array$definitionan optional array of definition for the option.

◆ count_options()

core\output\choicelist::count_options ( )

Get the number of options added to the choice list.

Return values
int

◆ export_for_template()

core\output\choicelist::export_for_template ( renderer_base $output)

Export for template.

Parameters
renderer_base$outputThe renderer.
Return values
array

Implements templatable.

◆ get_description()

core\output\choicelist::get_description ( )

Get the choice description option.

Return values
string|nullthe current description.

◆ get_selected_value()

core\output\choicelist::get_selected_value ( )

Get the selected option.

Return values
string|nullThe value of the selected option.

◆ get_template_name() [1/2]

core\output\choicelist::get_template_name ( renderer_base $renderer)

Get the name of the template to use for this templatable.

Parameters
renderer_base$rendererThe renderer requesting the template name
Return values
string

◆ get_template_name() [2/2]

core\output\named_templatable::get_template_name ( \renderer_base $renderer)
inherited

Get the name of the template to use for this templatable.

Parameters
renderer_base$rendererThe renderer requesting the template name
Return values
string

Implemented in core\output\local\dropdown\dialog, core\output\local\dropdown\status, core\output\sticky_footer, core_courseformat\output\local\content\cm\title, and qbank_viewquestionname\output\questionname.

◆ set_description()

core\output\choicelist::set_description ( string $value)

Set the general choice description option.

Parameters
string$valuethe new description.

◆ set_option_disabled()

core\output\choicelist::set_option_disabled ( string $value,
bool $disabled )

Set the option disabled.

Parameters
string$valueThe value of the option.
bool$disabledWhether the option is disabled.

◆ set_option_extras()

core\output\choicelist::set_option_extras ( string $value,
array $extras )

Set the option disabled.

Parameters
string$valueThe value of the option.
array$extrasan array to add HTML attributes to the option (attribute => value).

◆ set_selected_value()

core\output\choicelist::set_selected_value ( string $value)

Set the selected option.

Parameters
string$valueThe value of the selected option.

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