moodle/lib/form/format.php

98 lines
3.2 KiB
PHP
Raw Normal View History

<?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)
{
* Added setAdvanced functionality see http://docs.moodle.org/en/Development:lib/formslib.php_setAdvanced * Added MoodleQuickForm method closeHeaderBefore($elementName); http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition#Use_Fieldsets_to_group_Form_Elements * Added moodleform method add_action_buttons(); see http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition#add_action_buttons.28.24cancel_.3D_true.2C_.24revert_.3D_true.2C_.24submitlabel.3Dnull.29.3B * is_cancelled method added to moodleform http://docs.moodle.org/en/Development:lib/formslib.php_Usage#Basic_Usage_in_A_Normal_Page * added hidden labels to elements within groups such as the date_selector select boxes and other elements in 'groups' * quiz/mod.html migrated to formslib * glossary/edit.html migrated to formslib * extended registerNoSubmitButton() functionality to automatically add js to onclick to bypass client side js input validation. * added no_submit_button_pressed() function that can be used in a similar way to is_cancelled() as a test in the main script to see if some button in the page has been pressed that is a submit button that is used for some dynamic functionality within the form and not to submit the data for the whole form. * added new condition for disabledIf which allows to disable another form element if no options are selected from within a select element. * added default 'action' for moodleform - strip_querystring(qualified_me()) http://docs.moodle.org/en/Development:lib/formslib.php_Usage#Basic_Usage_in_A_Normal_Page
2006-12-19 07:03:08 +00:00
if ($elementName == null){
$elementName = 'format';
}
if ($elementLabel == null){
$elementLabel = get_string('format');
}
HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
$this->_type = 'format';
* Added setAdvanced functionality see http://docs.moodle.org/en/Development:lib/formslib.php_setAdvanced * Added MoodleQuickForm method closeHeaderBefore($elementName); http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition#Use_Fieldsets_to_group_Form_Elements * Added moodleform method add_action_buttons(); see http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition#add_action_buttons.28.24cancel_.3D_true.2C_.24revert_.3D_true.2C_.24submitlabel.3Dnull.29.3B * is_cancelled method added to moodleform http://docs.moodle.org/en/Development:lib/formslib.php_Usage#Basic_Usage_in_A_Normal_Page * added hidden labels to elements within groups such as the date_selector select boxes and other elements in 'groups' * quiz/mod.html migrated to formslib * glossary/edit.html migrated to formslib * extended registerNoSubmitButton() functionality to automatically add js to onclick to bypass client side js input validation. * added no_submit_button_pressed() function that can be used in a similar way to is_cancelled() as a test in the main script to see if some button in the page has been pressed that is a submit button that is used for some dynamic functionality within the form and not to submit the data for the whole form. * added new condition for disabledIf which allows to disable another form element if no options are selected from within a select element. * added default 'action' for moodleform - strip_querystring(qualified_me()) http://docs.moodle.org/en/Development:lib/formslib.php_Usage#Basic_Usage_in_A_Normal_Page
2006-12-19 07:03:08 +00:00
$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
/**
* 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':
$this->load(format_text_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);
}
}
?>