Merge branch 'MDL-78885-main' of https://github.com/rezaies/moodle

This commit is contained in:
Jun Pataleta
2024-03-25 23:37:57 +08:00
72 changed files with 723 additions and 817 deletions
+43 -7
View File
@@ -30,7 +30,9 @@ use templatable;
*/
class comboboxsearch implements renderable, templatable {
/** @var bool $renderlater Should the dropdown render straightaway? */
/** @var bool $renderlater Should the dropdown render straightaway? We sometimes need to output the component without all of the
* data and leave the rendering of any defaults and actual data to the caller. We will give you a basic placeholder that can
* then be easily replaced.*/
protected $renderlater;
/** @var string $buttoncontent What is the content of the "Button" that users will always see. */
@@ -54,18 +56,30 @@ class comboboxsearch implements renderable, templatable {
/** @var boolean $usesbutton Whether to provide a A11y button. */
protected $usesbutton;
/** @var null|string $label The label of the combobox. */
protected $label;
/** @var null|string $name The name of the input element representing the combobox. */
protected $name;
/** @var null|string $value The value of the input element representing the combobox. */
protected $value;
/**
* The class constructor.
*
* @param bool $renderlater How we figure out if we should render the template instantly.
* @param string $buttoncontent What gets placed in the button.
* @param ?string $dropdowncontent What can be placed in the dropdown if we are rendering now.
* @param ?string $dropdowncontent What will be placed in the dropdown if we are rendering now.
* @param ?string $parentclasses The classes that can be added that the bootstrap events are attached to.
* @param ?string $buttonclasses Any special classes that may be needed.
* @param ?string $dropdownclasses Any special classes that may be needed.
* @param ?string $buttonheader If the button item in the tertiary nav needs an extra top header for context.
* @param bool $usebutton If we want the mustache to add the button roles for us or do we have another aria role node?
* @throws moodle_exception If the implementor incorrectly call this module.
* @param ?string $buttonheader Sometimes we want extra context for a button before it is shown, basically a pseudo header.
* @param ?bool $usebutton If we want the mustache to add the button roles for us or do we have another aria role node?
* @param ?string $label The label of the combobox.
* @param ?string $name The name of the input element representing the combobox.
* @param ?string $value The value of the input element representing the combobox.
* @throws moodle_exception If the implementor incorrectly calls this module.
*/
public function __construct(
bool $renderlater,
@@ -75,7 +89,10 @@ class comboboxsearch implements renderable, templatable {
?string $buttonclasses = null,
?string $dropdownclasses = null,
?string $buttonheader = null,
?bool $usebutton = true
?bool $usebutton = true,
?string $label = null,
?string $name = null,
?string $value = null
) {
// Ensure implementors cant request to render the content now and not provide us any to show.
if (!$renderlater && empty($dropdowncontent)) {
@@ -87,6 +104,20 @@ class comboboxsearch implements renderable, templatable {
);
}
if ($usebutton && !$label) {
debugging(
'You have requested to use the button but have not provided a label for the combobox.',
DEBUG_DEVELOPER
);
}
if ($usebutton && !$name) {
debugging(
'You have requested to use the button but have not provided a name for the input element.',
DEBUG_DEVELOPER
);
}
$this->renderlater = $renderlater;
$this->buttoncontent = $buttoncontent;
$this->dropdowncontent = $dropdowncontent;
@@ -95,6 +126,9 @@ class comboboxsearch implements renderable, templatable {
$this->dropdownclasses = $dropdownclasses;
$this->buttonheader = $buttonheader;
$this->usesbutton = $usebutton;
$this->label = $label;
$this->name = $name;
$this->value = $value;
}
/**
@@ -105,7 +139,6 @@ class comboboxsearch implements renderable, templatable {
*/
public function export_for_template(renderer_base $output): array {
return [
'rtl' => right_to_left(),
'renderlater' => $this->renderlater,
'buttoncontent' => $this->buttoncontent ,
'dropdowncontent' => $this->dropdowncontent,
@@ -115,6 +148,9 @@ class comboboxsearch implements renderable, templatable {
'buttonheader' => $this->buttonheader,
'usebutton' => $this->usesbutton,
'instance' => rand(), // Template uniqid is per render out so sometimes these conflict.
'label' => $this->label,
'name' => $this->name,
'value' => $this->value,
];
}