forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat.php
126 lines (118 loc) · 4.55 KB
/
format.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
global $CFG;
require_once "$CFG->libdir/form/select.php";
/**
* HTML class for a editor format drop down element
*
* @author Jamie Pratt
* @access public
*/
class MoodleQuickForm_format extends MoodleQuickForm_select{
/**
* Whether we are using html editor.
*
* @var unknown_type
*/
var $_useHtmlEditor;
/**
* Class constructor
*
* @param string Select name attribute
* @param mixed Label(s) for the select
* @param mixed Either a typical HTML attribute string or an associative array
* @param mixed Either a string returned from can_use_html_editor() or false for no html editor
* default 'detect' tells element to use html editor if it is available.
* @access public
* @return void
*/
function MoodleQuickForm_format($elementName=null, $elementLabel=null, $attributes=null, $useHtmlEditor=null)
{
if ($elementName == null){
$elementName = 'format';
}
if ($elementLabel == null){
$elementLabel = get_string('format');
}
HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
$this->_type = 'format';
$this->_useHtmlEditor=$useHtmlEditor;
if ($this->_useHtmlEditor === null){
$this->_useHtmlEditor=can_use_html_editor();
}
$this->setPersistantFreeze($this->_useHtmlEditor);
if ($this->_useHtmlEditor){
$this->freeze();
} else {
$this->unfreeze();
}
} //end constructor
/**
* Add a single button.
*
* @param string $elementname name of the element to add the item to
* @param array $button arguments to pass to function $function
* @param boolean $suppresscheck whether to throw an error if the element
* doesn't exist.
* @param string $function - function to generate html from the arguments in $button
* @param string $function
*/
function setHelpButton($button, $function='helpbutton'){
global $OUTPUT;
//_elements has a numeric index, this code accesses the elements by name
$buttonparams = array('page', 'text', 'module', 'image', 'linktext', 'text', 'return', 'imagetext');
$helpiconoptions = array('page' => null, 'text' => null, 'module' => 'moodle', 'image' => null, 'linktext' => false);
foreach ($button as $key => $val) {
if (isset($button[$key])) {
$helpiconoptions[$buttonparams[$key]] = $val;
}
}
$helpicon = moodle_help_icon::make($helpiconoptions['page'], $helpiconoptions['text'], $helpiconoptions['module'], $helpiconoptions['linktext']);
if (!$helpiconoptions['image']) {
$helpicon->image = false;
}
$this->_helpbutton = $OUTPUT->help_icon($helpicon);
}
/**
* Called by HTML_QuickForm whenever form event is made on this element
*
* @param string $event Name of event
* @param mixed $arg event arguments
* @param object $caller calling object
* @since 1.0
* @access public
* @return mixed
*/
function onQuickFormEvent($event, $arg, &$caller)
{
switch ($event) {
case 'createElement':
$menu = format_text_menu();
$this->load($menu);
$this->setHelpButton(array('textformat', get_string('helpformatting')));
break;
case 'updateValue' :
$value = $this->_findValue($caller->_constantValues);
if (null === $value) {
$value = $this->_findValue($caller->_submitValues);
// Fix for bug #4465 & #5269
// XXX: should we push this to element::onQuickFormEvent()?
if (null === $value && (!$caller->isSubmitted() || !$this->getMultiple())) {
$value = $this->_findValue($caller->_defaultValues);
}
}
if (null !== $value) {
$format=$value;
}else{
$format=FORMAT_MOODLE;
}
if ($this->_useHtmlEditor){
$this->setValue(array(FORMAT_HTML));
}else{
$this->setValue(array($format));
}
return true;
break;
}
return parent::onQuickFormEvent($event, $arg, $caller);
}
}