diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 9f1b50ade5f..1ae249389a9 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -2595,8 +2595,7 @@ function print_single_button($link, $options, $label='OK', $method='get', $notus $form->id = $formid; if ($jsconfirmmessage) { - $confirmaction = new component_action('click', 'confirm_dialog', array('message' => $jsconfirmmessage)); - $form->button->add_action($confirmaction); + $form->button->add_confirm_action($jsconfirmmessage); } $output = $OUTPUT->button($form); diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index 933f3e80ae8..6113b09407a 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -220,6 +220,16 @@ class moodle_html_component { $this->label->text = $text; } } + + /** + * Shortcut for adding a JS confirm dialog when the component is clicked. + * The message must be a yes/no question. + * @param string $message The yes/no confirmation question. If "Yes" is clicked, the original action will occur. + * @return void + */ + public function add_confirm_action($message) { + $this->add_action(new component_action('click', 'confirm_dialog', array('message' => $message))); + } } /// Components representing HTML elements