]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-21198 new simple_button output component, this could finally solve potential...
authorPetr Skoda <skodak@moodle.org>
Sun, 3 Jan 2010 17:20:49 +0000 (17:20 +0000)
committerPetr Skoda <skodak@moodle.org>
Sun, 3 Jan 2010 17:20:49 +0000 (17:20 +0000)
lib/deprecatedlib.php
lib/outputcomponents.php
lib/outputrenderers.php

index 73046714623d3a9c86f5c9eb231c4b107f58d5ec..4c349fffa3c37bbf3f820d4e18cc99e792370643 100644 (file)
@@ -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);
 }
index e0404e77015696154f604fefd520e146f269d41b..2099790fc4b452f5f3fc02e6c44d1c3a85467945 100644 (file)
@@ -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}
index 2a281981ad81767885ecf93053c0f7f48dd1ec05..dc4bce5cfc8bd11df7ae152490281f002cffe84f 100644 (file)
@@ -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);