MDL-87694 core: headinglevel display option for $OUTPUT->confirm()

`\core\output\core_renderer::confirm()`'s `$displayoptions` parameter
now also accepts a `headinglevel` option that developers can use to
specify the heading level of the confirmation's heading. If not
specified, the confirmation heading will be rendered in an `h4` tag.
This commit is contained in:
Jun Pataleta
2026-02-02 09:24:53 -08:00
committed by Stefan Topfstedt
parent aa24806a89
commit f3b0bb1896
2 changed files with 33 additions and 12 deletions
@@ -0,0 +1,9 @@
issueNumber: MDL-87694
notes:
core:
- message: >-
`\core\output\core_renderer::confirm()`'s `$displayoptions` parameter
now also accepts a `headinglevel` option that developers can use to
specify the heading level of the confirmation's heading. If not
specified, the confirmation heading will be rendered in an `h4` tag.
type: changed
+24 -12
View File
@@ -1697,23 +1697,35 @@ class core_renderer extends renderer_base {
return $this->action_link($url, $text . $icon, $action, $attributes);
}
/**
* Print a message along with button choices for Continue/Cancel
*
* If a string or moodle_url is given instead of a single_button, method defaults to post.
*
* @param string $message The question to ask the user
* @param single_button|moodle_url|string $continue The single_button component representing the Continue answer. Can also be a moodle_url or string URL
* @param single_button|moodle_url|string $cancel The single_button component representing the Cancel answer. Can also be a moodle_url or string URL
* @param array $displayoptions optional extra display options
* @return string HTML fragment
*/
/**
* Print a message along with button choices for Continue/Cancel
*
* If a string or moodle_url is given instead of a single_button, method defaults to post.
*
* @param string $message The question to ask the user
* @param single_button|moodle_url|string $continue The single_button component representing the Continue answer.
* Can also be a moodle_url or string URL
* @param single_button|moodle_url|string $cancel The single_button component representing the Cancel answer.
* Can also be a moodle_url or string URL
* @param array $displayoptions Display options (Optional).
* Possible options:
* - confirmtitle: The title to display above the message
* - continuestr: The label to use for the continue button (if $continue is not a single_button)
* - cancelstr: The label to use for the cancel button (if $cancel is not a single_button)
* - headinglevel: The heading level to use for the title (1-6). Default is 4.
* - type: The button type to use for the continue button (if $continue is not a single_button). Default is BUTTON_PRIMARY.
* @return string HTML fragment
*/
public function confirm($message, $continue, $cancel, array $displayoptions = []) {
// Check existing displayoptions.
$displayoptions['confirmtitle'] = $displayoptions['confirmtitle'] ?? get_string('confirm');
$displayoptions['continuestr'] = $displayoptions['continuestr'] ?? get_string('continue');
$displayoptions['cancelstr'] = $displayoptions['cancelstr'] ?? get_string('cancel');
$headinglevel = $displayoptions['headinglevel'] ?? 4;
if ($headinglevel < 1 || $headinglevel > 6) {
throw new coding_exception('The headinglevel option to $OUTPUT->confirm() must be between 1 and 6.');
}
if ($continue instanceof single_button) {
// Continue button should be primary if set to secondary type as it is the fefault.
@@ -1758,7 +1770,7 @@ class core_renderer extends renderer_base {
$output = $this->box_start('generalbox modal modal-dialog modal-in-page show', 'notice', $attributes);
$output .= $this->box_start('modal-content', 'modal-content');
$output .= $this->box_start('modal-header px-3', 'modal-header');
$output .= html_writer::tag('h4', $displayoptions['confirmtitle']);
$output .= html_writer::tag('h' . $headinglevel, $displayoptions['confirmtitle'], ['class' => 'h4']);
$output .= $this->box_end();
$attributes = [
'role' => 'alert',