Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
core\output\choicelist Class Reference
Inheritance diagram for core\output\choicelist:
renderable core\output\named_templatable templatable

Public Member Functions

 __construct (?string $description=null)
 Constructor.
 
 add_option (string $value, string $name, array $definition=[])
 Add option to the user choice.
 
 add_option_extras (string $value, array $extras)
 Add HTML attributes to the option.
 
 count_options ()
 Get the number of options added to the choice list.
 
 export_for_template (renderer_base $output)
 Export for template.
 
 get_allow_empty ()
 Get the allow empty option.
 
 get_description ()
 Get the choice description option.
 
 get_option_extras (string $value)
 Retrieves the HTML attributes for a given value from the options array.
 
 get_selectable_options ()
 Get the selectable options.
 
 get_selected_content (renderer_base $output)
 Get the selected option HTML.
 
 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.
 
 has_value (string $value)
 Check if the value is in the options.
 
 set_allow_empty (bool $allowempty)
 Set the allow empty option.
 
 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)
 Sets the HTML attributes to the option.
 
 set_selected_value (string $value)
 Set the selected option.
 

Protected Attributes

bool $allowempty = null
 if the selected value can be empty.
 
string $description = null
 the choice description.
 
object[] $options = []
 The user choices.
 
string $selected = null
 the selected option.
 

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.

◆ add_option_extras()

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

Add HTML attributes to the option.

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

◆ 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_allow_empty()

core\output\choicelist::get_allow_empty ( )

Get the allow empty option.

Return values
boolWhether the selected value can be empty.

◆ get_description()

core\output\choicelist::get_description ( )

Get the choice description option.

Return values
string|nullthe current description.

◆ get_option_extras()

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

Retrieves the HTML attributes for a given value from the options array.

Parameters
string$valueThe value for which to retrieve the extras.
Return values
arrayan array of HTML attributes of the option (attribute => value).

◆ get_selectable_options()

core\output\choicelist::get_selectable_options ( )

Get the selectable options.

This method returns an array of options that are selectable, excluding the selected option and any disabled options.

Return values
stdClass[]

◆ get_selected_content()

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

Get the selected option HTML.

This method is used to display the selected option and the option icon.

Parameters
renderer_base$outputThe renderer.
Return values
string

◆ 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, mod_quiz\output\list_of_attempts, and qbank_viewquestionname\output\questionname.

◆ has_value()

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

Check if the value is in the options.

Parameters
string$valueThe value to check.
Return values
bool

◆ set_allow_empty()

core\output\choicelist::set_allow_empty ( bool $allowempty)

Set the allow empty option.

Parameters
bool$allowemptyWhether the selected value can be empty.

◆ 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 )

Sets the HTML attributes to the option.

This method will remove any previous extra attributes.

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: