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:
Petr Skoda
2010-01-03 15:46:14 +00:00
parent 3cd5305f11
commit 5c2ed7e215
62 changed files with 170 additions and 243 deletions
+3 -1
View File
@@ -5263,7 +5263,9 @@ function admin_externalpage_print_header($focus='') {
$caption = get_string('blocksediton');
$options['adminedit'] = 'on';
}
$buttons = $OUTPUT->button(html_form::make_button($PAGE->url->out(), $options, $caption, 'get'));
$url = clone($PAGE->url);
$url->params($options);
$buttons = $OUTPUT->single_button($url, $caption, 'get');
}
$PAGE->set_title("$SITE->shortname: " . implode(": ",$visiblepathtosection));
+6 -8
View File
@@ -2472,7 +2472,7 @@ function button_to_popup_window ($url, $name=null, $linkname=null,
$id=null, $class=null) {
global $OUTPUT;
debugging('button_to_popup_window() has been deprecated. Please change your code to use $OUTPUT->button().');
debugging('button_to_popup_window() has been deprecated. Please change your code to use $OUTPUT->single_button().');
if ($options == 'none') {
$options = null;
@@ -2516,7 +2516,7 @@ function button_to_popup_window ($url, $name=null, $linkname=null,
}
$form->button->add_action(new popup_action('click', $url, $name, $popupparams));
$output = $OUTPUT->button($form);
$output = $OUTPUT->single_button($form);
if ($return) {
return $output;
@@ -2546,7 +2546,7 @@ function print_single_button($link, $options, $label='OK', $method='get', $notus
$return=false, $tooltip='', $disabled = false, $jsconfirmmessage='', $formid = '') {
global $OUTPUT;
debugging('print_single_button() has been deprecated. Please change your code to use $OUTPUT->button().');
debugging('print_single_button() has been deprecated. Please change your code to use $OUTPUT->single_button().');
// Cast $options to array
$options = (array) $options;
@@ -2562,7 +2562,7 @@ function print_single_button($link, $options, $label='OK', $method='get', $notus
$form->button->add_confirm_action($jsconfirmmessage);
}
$output = $OUTPUT->button($form);
$output = $OUTPUT->single_button($form);
if ($return) {
return $output;
@@ -3561,10 +3561,8 @@ function update_module_button($cmid, $ignored, $string) {
if (has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_MODULE, $cmid))) {
$string = get_string('updatethis', '', $string);
$form = new html_form();
$form->url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
$form->button->text = $string;
return $OUTPUT->button($form);
$url = new moodle_url("$CFG->wwwroot/course/mod.php", array('update' => $cmid, 'return' => true, 'sesskey' => sesskey()));
return $OUTPUT->single_button($url, $string);
} else {
return '';
}
+11 -5
View File
@@ -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)) {
@@ -116,17 +116,14 @@ $DB = $realdb;
echo $OUTPUT->container_start();
$form = html_form::make_button($baseurl, array('action' => 'setup'), 'Set up test tables', 'get');
$form->button->disabled = $issetup > 0;
echo $OUTPUT->button($form);
$aurl = new moodle_url($baseurl, array('action' => 'setup'));
echo $OUTPUT->single_button($aurl, 'Set up test tables', 'get', array('disabled'=>($issetup > 0)));
$form = html_form::make_button($baseurl, array('action' => 'teardown'), 'Drop test tables', 'get');
$form->button->disabled = $issetup == 0;
echo $OUTPUT->button($form);
$aurl = new moodle_url($baseurl, array('action' => 'teardown'));
echo $OUTPUT->single_button($aurl, 'Drop test tables', 'get', array('disabled'=>($issetup == 0)));
$form = html_form::make_button($baseurl, array('action' => 'test'), 'Run tests', 'get');
$form->button->disabled = $issetup != count($requiredtables);
echo $OUTPUT->button($form);
$aurl = new moodle_url($baseurl, array('action' => 'test'));
echo $OUTPUT->single_button($aurl, 'Run tests', 'get', array('disabled'=>($issetup != count($requiredtables))));
echo $OUTPUT->container_end();
+1 -1
View File
@@ -2218,7 +2218,7 @@ function switchroles_form($courseid) {
$options['sesskey'] = sesskey();
$options['switchrole'] = 0;
return $OUTPUT->button(html_form::make_button($CFG->wwwroot.'/course/view.php', $options, get_string('switchrolereturn')));
return $OUTPUT->single_button(new moodle_url($CFG->wwwroot.'/course/view.php', $options), get_string('switchrolereturn'));
}
if (has_capability('moodle/role:switchroles', $context)) {