2 require_once("HTML/QuickForm/text.php");
5 * HTML class for a url type element
10 class MoodleQuickForm_url
extends HTML_QuickForm_text
{
12 * html for help button, if empty then no help
17 var $_hiddenLabel=false;
19 function MoodleQuickForm_url($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
21 require_once("$CFG->dirroot/repository/lib.php");
22 $options = (array)$options;
23 foreach ($options as $name=>$value) {
24 $this->_options
[$name] = $value;
26 if (!isset($this->_options
['usefilepicker'])) {
27 $this->_options
['usefilepicker'] = true;
29 parent
::HTML_QuickForm_text($elementName, $elementLabel, $attributes);
32 function setHiddenLabel($hiddenLabel){
33 $this->_hiddenLabel
= $hiddenLabel;
36 global $CFG, $COURSE, $USER, $PAGE, $OUTPUT;
38 $id = $this->_attributes
['id'];
39 $elname = $this->_attributes
['name'];
41 if ($this->_hiddenLabel
) {
43 $str = '<label class="accesshide" for="'.$this->getAttribute('id').'" >'.
44 $this->getLabel().'</label>'.parent
::toHtml();
46 $str = parent
::toHtml();
48 if (empty($this->_options
['usefilepicker'])) {
51 $strsaved = get_string('filesaved', 'repository');
52 $straddlink = get_string('choosealink', 'repository');
53 if ($COURSE->id
== SITEID
) {
54 $context = get_context_instance(CONTEXT_SYSTEM
);
56 $context = get_context_instance(CONTEXT_COURSE
, $COURSE->id
);
58 $client_id = uniqid();
61 <button id="filepicker-button-{$client_id}" style="display:none">
65 $args = new stdClass();
66 $args->accepted_types
= '*';
67 $args->return_types
= FILE_EXTERNAL
;
68 $args->context
= $PAGE->context
;
69 $args->client_id
= $client_id;
71 $fp = new file_picker($args);
72 $options = $fp->options
;
74 // print out file picker
75 $str .= $OUTPUT->render($fp);
77 $module = array('name'=>'form_url', 'fullpath'=>'/lib/form/url.js', 'requires'=>array('core_filepicker'));
78 $PAGE->requires
->js_init_call('M.form_url.init', array($options), true, $module);
79 $PAGE->requires
->js_function_call('show_item', array('filepicker-button-'.$client_id));
84 * Automatically generates and assigns an 'id' attribute for the element.
86 * Currently used to ensure that labels work on radio buttons and
87 * checkboxes. Per idea of Alexander Radivanovich.
88 * Overriden in moodleforms to remove qf_ prefix.
93 function _generateId()
97 if (!$this->getAttribute('id')) {
98 $this->updateAttributes(array('id' => 'id_'. substr(md5(microtime() . $idx++
), 0, 6)));
100 } // end func _generateId
102 * set html for help button
105 * @param array $help array of arguments to make a help button
106 * @param string $function function name to call to get html
108 function setHelpButton($helpbuttonargs, $function='helpbutton'){
109 debugging('component setHelpButton() is not used any more, please use $mform->setHelpButton() instead');
112 * get html for help button
115 * @return string html for help button
117 function getHelpButton(){
118 return $this->_helpbutton
;
121 * Slightly different container template when frozen. Don't want to use a label tag
122 * with a for attribute in that case for the element label but instead use a div.
123 * Templates are defined in renderer constructor.
127 function getElementTemplateType(){
128 if ($this->_flagFrozen
){