MDL-21198 $OUTPUT->single_button() resurrection, hopefully much easier to use than $OUTPUT->button(); fixed some regressions and code style improvements
This commit is contained in:
+11
-5
@@ -995,20 +995,26 @@ class core_renderer extends renderer_base {
|
||||
|
||||
/**
|
||||
* Returns a form with single button.
|
||||
* If first parameter is html_form instance all other parameters are ignored.
|
||||
*
|
||||
* @param string|moodle_url|html_form $url_or_form
|
||||
* @param string $label button text
|
||||
* @param string $method get or post submit method
|
||||
* @param array $options associative array {disabled, title}
|
||||
* @return string HTML fragment
|
||||
*/
|
||||
public function single_button($url_or_form, $label=null, $method='get') {
|
||||
public function single_button($url_or_form, $label=null, $method='post', array $options=null) {
|
||||
if ($url_or_form instanceof html_form) {
|
||||
$form = clone($url_or_form);
|
||||
if (!is_null($label)) {
|
||||
$form->button->text = $label;
|
||||
$form = $url_or_form;
|
||||
if (func_num_args() > 1) {
|
||||
debugging('html_form instance used as first parameter of $OUTPUT->single_button(), all other parameters are ignored.');
|
||||
}
|
||||
} else {
|
||||
$form = html_form::make_button($url_or_form, null, $label, $method);
|
||||
$form->button->disabled = !empty($options['disabled']);
|
||||
if (!empty($options['title'])) {
|
||||
$form->button->title = $options['title'];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->button($form);
|
||||
@@ -1058,7 +1064,7 @@ class core_renderer extends renderer_base {
|
||||
$buttonoutput = null;
|
||||
|
||||
if (empty($contents) && !empty($form->button)) {
|
||||
debugging("You probably want to use \$OUTPUT->button(\$form), please read that function's documentation", DEBUG_DEVELOPER);
|
||||
debugging("You probably want to use \$OUTPUT->single_button(\$form), please read that function's documentation", DEBUG_DEVELOPER);
|
||||
} else if (empty($contents)) {
|
||||
$contents = $this->output_empty_tag('input', array('type' => 'submit', 'value' => get_string('ok')));
|
||||
} else if (!empty($form->button)) {
|
||||
|
||||
Reference in New Issue
Block a user