From: Petr Skoda <skodak@moodle.org>
Date: Sun, 3 Jan 2010 17:20:49 +0000 (+0000)
Subject: MDL-21198 new simple_button output component, this could finally solve potential... 
X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=26eab8d4f50cdecfe8328d47331e0c79257c5340;p=moodle.git

MDL-21198 new simple_button output component, this could finally solve potential "form x button" confusion - continued
---

diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php
index 7304671462..4c349fffa3 100644
--- a/lib/deprecatedlib.php
+++ b/lib/deprecatedlib.php
@@ -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);
 }
diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php
index e0404e7701..2099790fc4 100644
--- a/lib/outputcomponents.php
+++ b/lib/outputcomponents.php
@@ -1547,6 +1547,7 @@ class html_form extends html_component {
 
     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) {
@@ -1569,7 +1570,7 @@ class html_form extends html_component {
 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}
diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php
index 2a281981ad..dc4bce5cfc 100644
--- a/lib/outputrenderers.php
+++ b/lib/outputrenderers.php
@@ -970,20 +970,20 @@ class core_renderer extends renderer_base {
     * @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');
@@ -997,20 +997,22 @@ 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|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);