]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-21198 towards origianl single_button() syntax + other improvements
authorPetr Skoda <skodak@moodle.org>
Sun, 3 Jan 2010 10:28:29 +0000 (10:28 +0000)
committerPetr Skoda <skodak@moodle.org>
Sun, 3 Jan 2010 10:28:29 +0000 (10:28 +0000)
lib/outputcomponents.php
lib/outputrenderers.php

index e5c3f66d86d52a25175b1938c2b0c026d73ac5cb..c1f0d07a486d3631716cec9d8f9cf6b2387667aa 100644 (file)
@@ -1521,9 +1521,10 @@ class html_form extends html_component {
      * Constructor: sets up the other components in case they are needed
      * @return void
      */
-    public function __construct() {
+    public function __construct(array $options = null) {
+        parent::__construct($options);
         $this->button = new html_button();
-        $this->button->text = get_string('yes');
+        $this->button->text = get_string('ok');
     }
 
     /**
@@ -1547,14 +1548,14 @@ class html_form extends html_component {
         parent::prepare($output, $page, $target);
     }
 
-    public static function make_button($url, array $params=null, $label=null, $method='post') {
-        if ($label === null) {
-            $label = get_string('ok');
-        }
-        $form = new html_form();
+    public static function make_button($url, array $params=null, $label=null, $method='post', array $formoptions=null) {
+        $form = new html_form($formoptions);
         $form->url = new moodle_url($url, $params);
-        $form->button->text = $label;
+        if ($label !== null) {
+            $form->button->text = $label;
+        }
         $form->method = $method;
+
         return $form;
     }
 }
index 2192839db4a04adc9edcf5f50f95e15d30a3542c..6461ae5468945762f5728bcea218dcf34dacb539 100644 (file)
@@ -993,13 +993,34 @@ class core_renderer extends renderer_base {
         return $output;
     }
 
+    /**
+     * Returns a form with single button.
+     *
+     * @param string|moodle_url|html_form $url_or_form 
+     * @param string $label button text
+     * @param string $method get or post submit method
+     * @return string HTML fragment
+     */
+    public function single_button($url_or_form, $label=null, $method='get') {
+        if ($url_or_form instanceof html_form) {
+            $form = clone($url_or_form);
+            if (!is_null($label)) {
+                $form->button->text = $label;
+            }
+        } else {
+            $form = html_form::make_button($url_or_form, null, $label, $method);
+        }
+
+        return $this->button($form);
+    }
+
     /**
      * Given a html_form object, outputs an <input> tag within a form that uses the object's attributes.
      *
      * @param html_form $form A html_form object
      * @return string HTML fragment
      */
-    public function button($form) {
+    public function button(html_form $form) {
         if (empty($form->button) or !($form->button instanceof html_button)) {
             throw new coding_exception('$OUTPUT->button($form) requires $form to have a button (html_button) value');
         }
@@ -1030,7 +1051,7 @@ class core_renderer extends renderer_base {
      * @param string $contents HTML fragment to put inside the form. If given, must contain at least the submit button.
      * @return string HTML fragment
      */
-    public function form($form, $contents=null) {
+    public function form(html_form $form, $contents=null) {
         $form = clone($form);
         $form->prepare($this, $this->page, $this->target);
         $this->prepare_event_handlers($form);