From 6a5c71b95c1348f6863ae6435a19edf51ef9f072 Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Tue, 4 Aug 2009 02:42:24 +0000 Subject: [PATCH] MDL-19756 Migrated print_textfield, choose_from_radio and print_checkbox --- lib/deprecatedlib.php | 37 ++++++++++++++++- lib/outputlib.php | 97 ++++++++++++++++++++++++++++++++++++++++++- lib/weblib.php | 44 -------------------- 3 files changed, 131 insertions(+), 47 deletions(-) diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 60c42b09ff..a9c63aa4c6 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -3449,7 +3449,7 @@ function print_checkbox ($name, $value, $checked = true, $label = '', $alt = '', // debugging('print_checkbox() has been deprecated. Please change your code to use $OUTPUT->checkbox($checkbox).'); global $OUTPUT; - + if (!empty($script)) { debugging('The use of the $script param in print_checkbox has not been migrated into $OUTPUT->checkbox. Please use $checkbox->add_action().', DEBUG_DEVELOPER); } @@ -3470,3 +3470,38 @@ function print_checkbox ($name, $value, $checked = true, $label = '', $alt = '', } } + + +/** + * Display an standard html text field with an optional label + * + * @deprecated since Moodle 2.0 + * + * @param string $name The name of the text field + * @param string $value The value of the text field + * @param string $alt The info to be inserted in the alt tag + * @param int $size Sets the size attribute of the field. Defaults to 50 + * @param int $maxlength Sets the maxlength attribute of the field. Not set by default + * @param bool $return Whether this function should return a string or output + * it (defaults to false) + * @return string|void If $return=true returns string, else echo's and returns void + */ +function print_textfield ($name, $value, $alt = '',$size=50,$maxlength=0, $return=false) { + + // debugging('print_textfield() has been deprecated. Please change your code to use $OUTPUT->textfield($field).'); + + global $OUTPUT; + + $field = html_field::make_text($name, $value, $alt, $maxlength); + $field->style = "width: {$size}px;"; + + $output = $OUTPUT->textfield($field); + + if (empty($return)) { + echo $output; + } else { + return $output; + } + +} + diff --git a/lib/outputlib.php b/lib/outputlib.php index 4800459186..4a342f969b 100644 --- a/lib/outputlib.php +++ b/lib/outputlib.php @@ -2924,7 +2924,6 @@ class moodle_core_renderer extends moodle_renderer_base { } $option->prepare(); - $option->generate_id(); $option->label->for = $option->id; $this->prepare_event_handlers($option); @@ -3015,6 +3014,28 @@ class moodle_core_renderer extends moodle_renderer_base { } } + /** + * Output an element + * + * @param html_field $field a html_field object + * @return string the HTML for the + */ + public function textfield($field) { + $field->prepare(); + $this->prepare_event_handlers($field); + $output = $this->output_start_tag('span', array('class' => "textfield $field->name")); + $output .= $this->output_empty_tag('input', array( + 'type' => 'text', + 'name' => $field->name, + 'id' => $field->id, + 'value' => $field->value, + 'style' => $field->style, + 'alt' => $field->alt, + 'maxlength' => $field->maxlength)); + $output .= $this->output_end_tag('span'); + return $output; + } + /** * Outputs a