]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19756 Added shortcut to html_select_option to make checkboxes
authornicolasconnault <nicolasconnault>
Thu, 6 Aug 2009 06:58:14 +0000 (06:58 +0000)
committernicolasconnault <nicolasconnault>
Thu, 6 Aug 2009 06:58:14 +0000 (06:58 +0000)
lib/deprecatedlib.php
lib/outputlib.php

index 0d96eecc6cbeeb75bbeaa9aef5c52d01e3b1cbaa..64b5d4a38040def1f21d5a7188a89bf50699d7b4 100644 (file)
@@ -3393,14 +3393,7 @@ function print_checkbox ($name, $value, $checked = true, $label = '', $alt = '',
         debugging('The use of the $script param in print_checkbox has not been migrated into $OUTPUT->checkbox. Please use $checkbox->add_action().', DEBUG_DEVELOPER);
     }
 
-    $checkbox = new html_select_option();
-    $checkbox->value = $value;
-    $checkbox->selected = $checked;
-    $checkbox->text = $label;
-    $checkbox->label->text = $label;
-    $checkbox->alt = $alt;
-
-    $output = $OUTPUT->checkbox($checkbox, $name);
+    $output = $OUTPUT->checkbox(html_select_option::make_checkbox($value, $checked, $label, $alt), $name);
 
     if (empty($return)) {
         echo $output;
index f8a42c820221fa2376ddbef36c2414384dc6610b..8b9adba68f9f97d60e7f96910bd6c76e524de540 100644 (file)
@@ -4184,6 +4184,24 @@ class html_select_option extends moodle_html_component {
 
         parent::prepare();
     }
+
+    /**
+     * Shortcut for making a checkbox-ready option
+     * @param string $value The value of the checkbox
+     * @param boolean $checked
+     * @param string $label
+     * @param string $alt
+     * @return html_select_option A component ready for $OUTPUT->checkbox()
+     */
+    public function make_checkbox($value, $checked, $label='', $alt='') {
+        $checkbox = new html_select_option();
+        $checkbox->value = $value;
+        $checkbox->selected = $checked;
+        $checkbox->text = $label;
+        $checkbox->label->text = $label;
+        $checkbox->alt = $alt;
+        return $checkbox;
+    }
 }
 
 /**