Skip to content

Commit

Permalink
MDL-21198 new simple_button output component, this could finally solv…
Browse files Browse the repository at this point in the history
…e potential "form x button" confusion - continued
  • Loading branch information
skodak committed Jan 3, 2010
1 parent d894edd commit 26eab8d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/deprecatedlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3009,8 +3009,8 @@ function notice_yesno($message, $linkyes, $linkno, $optionsyes=NULL, $optionsno=

global $OUTPUT;

$buttoncontinue = html_form::make_button($linkyes, $optionsyes, get_string('yes'), $methodyes);
$buttoncancel = html_form::make_button($linkno, $optionsno, get_string('no'), $methodno);
$buttoncontinue = new simple_button(new moodle_url($linkyes, $optionsyes), get_string('yes'), $methodyes);
$buttoncancel = new simple_button(new moodle_url($linkno, $optionsno), get_string('no'), $methodno);

echo $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/outputcomponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,7 @@ public function prepare(renderer_base $output, moodle_page $page, $target) {

public static function make_button($url, array $params=null, $label=null, $method='post', array $formoptions=null) {
//TODO: to be removed soon, repalced by ew single_button()
// in any case the $params argument is not appropriate here, we use moodle_urls now!
$form = new html_form($formoptions);
$form->url = new moodle_url($url, $params);
if ($label !== null) {
Expand All @@ -1569,7 +1570,7 @@ public static function make_button($url, array $params=null, $label=null, $metho
class single_button extends html_form {
/**
* Constructor
* @param string|moodle_url
* @param string|moodle_url
* @param string $label button text
* @param string $method get or post submit method
* @param array $options associative array form attributes + {disabled, title}
Expand Down
24 changes: 13 additions & 11 deletions lib/outputrenderers.php
Original file line number Diff line number Diff line change
Expand Up @@ -970,20 +970,20 @@ public function link($link_or_url, $text = null, array $options = null) {
* @return string HTML fragment
*/
public function confirm($message, $continue, $cancel) {
if ($continue instanceof html_form) {
if ($continue instanceof html_form) { //TODO: change to single_button
$continue = clone($continue);
} else if (is_string($continue) or $continue instanceof moodle_url) {
$continue = html_form::make_button($continue, null, get_string('continue'), 'post');
$continue = new single_button($continue, get_string('continue'), 'post');
} else {
throw new coding_exception('The continue param to $OUTPUT->confirm must be either a URL (string/moodle_url) or a html_form object.');
throw new coding_exception('The continue param to $OUTPUT->confirm() must be either a URL (string/moodle_url) or a html_form instance.');
}

if ($cancel instanceof html_form) {
if ($cancel instanceof html_form) { //TODO: change to single_button
$cancel = clone($cancel);
} else if (is_string($cancel) or $cancel instanceof moodle_url) {
$cancel = html_form::make_button($cancel, null, get_string('cancel'), 'get');
$cancel = new single_button($cancel, get_string('cancel'), 'get');
} else {
throw new coding_exception('The cancel param to $OUTPUT->confirm must be either a URL (string/moodle_url) or a html_form object.');
throw new coding_exception('The cancel param to $OUTPUT->confirm() must be either a URL (string/moodle_url) or a html_form instance.');
}

$output = $this->box_start('generalbox', 'notice');
Expand All @@ -997,20 +997,22 @@ public function confirm($message, $continue, $cancel) {
* Returns a form with single button.
* If first parameter is html_form instance all other parameters are ignored.
*
* @param string|moodle_url|single_button $singlebutton_or_form
* @param string|moodle_url|single_button $url_or_singlebutton
* @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($singlebutton_or_form, $label=null, $method='post', array $options=null) {
if ($singlebutton_or_form instanceof single_button) {
$button = $singlebutton_or_form;
public function single_button($url_or_singlebutton, $label=null, $method='post', array $options=null) {
if ($url_or_singlebutton instanceof single_button) {
$button = $url_or_singlebutton;
if (func_num_args() > 1) {
debugging('html_form instance used as first parameter of $OUTPUT->single_button(), all other parameters are ignored.');
}
} else if ($url_or_singlebutton instanceof single_button or is_string($url_or_singlebutton)) {
$button = new single_button($url_or_singlebutton, $label, $method, $options);
} else {
$button = new single_button($url_or_form, $label, $method, $options);
throw new coding_exception('The $$url_or_singlebutton param to $OUTPUT->single_button() must be either a URL (string/moodle_url) or a single_button instance.');
}

return $this->button($button);
Expand Down

0 comments on commit 26eab8d

Please sign in to comment.