moodle_local_treestudyplan/classes/form/text_integer.php

77 lines
2.9 KiB
PHP
Raw Normal View History

<?php
namespace local_treestudyplan\form;
use MoodleQuickForm_text;
use MoodleQuickForm;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . "/form/text.php");
class text_integer extends MoodleQuickForm_text {
/**
* Accepts a renderer
*
* @param object $renderer An HTML_QuickForm_Renderer object
* @param bool $required Whether an element is required
* @param string $error An error message associated with an element
* @return void
*/
public function accept(&$renderer, $required = false, $error = null) {
global $OUTPUT;
$elementname = $this->getName();
// Make sure the element has an id.
$this->_generateId();
$advanced = isset($renderer->_advancedElements[$elementname]);
$elementcontext = $this->export_for_template($OUTPUT);
$helpbutton = '';
if (method_exists($this, 'getHelpButton')) {
$helpbutton = $this->getHelpButton();
}
$label = $this->getLabel();
$unsigned = (isset($this->_attributes['unsigned']) && $this->_attributes['unsigned']);
$nonzero = (isset($this->_attributes['nonzero']) && $this->_attributes['nonzero']);
$context = array(
'element' => $elementcontext,
'label' => $label,
2024-06-02 19:23:40 +02:00
'unsigned' => ($unsigned) ? true : false ,
'nonzero' => ($nonzero) ? true : false ,
'required' => $required,
'advanced' => $advanced,
'helpbutton' => $helpbutton,
'error' => $error,
);
$html = $OUTPUT->render_from_template('local_treestudyplan/form/element_text_integer', $context);
if ($renderer->_inGroup) {
$this->_groupElementTemplate = $html;
}
if (($renderer->_inGroup) && !empty($renderer->_groupElementTemplate)) {
$renderer->_groupElementTemplate = $html;
} else if (!isset($renderer->_templates[$elementname])) {
$renderer->_templates[$elementname] = $html;
}
if (in_array($elementname, $renderer->_stopFieldsetElements) && $renderer->_fieldsetsOpen > 0) {
$renderer->_html .= $renderer->_closeFieldsetTemplate;
$renderer->_fieldsetsOpen--;
}
$renderer->_html .= $html;
}
public static function Register() {
global $CFG;
MoodleQuickForm::registerElementType(
// The custom element is named `course_competency_rule`.
// This is the element name used in the `addElement()` function.
'text_integer',
// This is where it's definition is defined.
// This does not currently support class auto-loading.
"$CFG->dirroot/local/treestudyplan/classes/form/text_integer.php",
// The class name of the element.
'local_treestudyplan\form\text_integer'
);
}
}