Search moodle.org's
Developer Documentation

See Release Notes

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

(no description)

File Size: 207 lines (6 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: choicelist  - X-Ref

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.

__construct(?string $description = null)   X-Ref
Constructor.

param: string $description the choice description.

add_option(string $value, string $name, array $definition = [])   X-Ref
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).

param: string $value
param: string $name
param: array $definition an optional array of definition for the option.

count_options()   X-Ref
Get the number of options added to the choice list.

return: int

set_selected_value(string $value)   X-Ref
Set the selected option.

param: string $value The value of the selected option.

get_selected_value()   X-Ref
Get the selected option.

return: string|null The value of the selected option.

set_description(string $value)   X-Ref
Set the general choice description option.

param: string $value the new description.

get_description()   X-Ref
Get the choice description option.

return: string|null the current description.

set_option_disabled(string $value, bool $disabled)   X-Ref
Set the option disabled.

param: string $value The value of the option.
param: bool $disabled Whether the option is disabled.

set_option_extras(string $value, array $extras)   X-Ref
Set the option disabled.

param: string $value The value of the option.
param: array $extras an array to add HTML attributes to the option (attribute => value).

export_for_template(renderer_base $output)   X-Ref
Export for template.

param: renderer_base $output The renderer.
return: array

get_template_name(renderer_base $renderer)   X-Ref
Get the name of the template to use for this templatable.

param: renderer_base $renderer The renderer requesting the template name
return: string