MDL-62947 mod_feedback: fix feedback so it correctly uses forms API

Feedback code was doing the following, which is incompatible with the
sec-patched quickforms lib:
- appending '[0]' to non-group element names, meaning type checks in
getCleanType() were falling back to PARAM_RAW instead of PARAM_INT,
and meaning _findValue() was comparing elements it thought to be arrays
with scalar submit values (worked with eval() implementation as the 0th
element of a string was the character, but not working when patched).
- external unit tests incorrectly testing multichoice questions in the
process_page tests - patched lib highlighted failures.

It was also doing the following:
- actively setting null as default element values instead of 0 for
radio buttons and dropdowns (for 'not selected'). This is incompatible
with more recent quickforms lib (see MDL-63070).
- creating groups using addElement instead of addGroup - not recommended

This patch addresses the above.
This commit is contained in:
Jake Dallimore
2018-09-05 12:12:20 +08:00
committed by Jun Pataleta
parent c87010baca
commit c96c9601af
3 changed files with 40 additions and 21 deletions
+14 -7
View File
@@ -293,15 +293,22 @@ class mod_feedback_complete_form extends moodleform {
*/
public function add_form_element($item, $element, $addrequiredrule = true, $setdefaultvalue = true) {
global $OUTPUT;
// Add element to the form.
if (is_array($element)) {
if ($this->is_frozen() && $element[0] === 'text') {
// Convert 'text' element to 'static' when freezing for better display.
$element = ['static', $element[1], $element[2]];
if (is_array($element) && $element[0] == 'group') {
// For groups, use the mforms addGroup API.
// $element looks like: ['group', $groupinputname, $name, $objects, $separator, $appendname],
$element = $this->_form->addGroup($element[3], $element[1], $element[2], $element[4], $element[5]);
} else {
// Add non-group element to the form.
if (is_array($element)) {
if ($this->is_frozen() && $element[0] === 'text') {
// Convert 'text' element to 'static' when freezing for better display.
$element = ['static', $element[1], $element[2]];
}
$element = call_user_func_array(array($this->_form, 'createElement'), $element);
}
$element = call_user_func_array(array($this->_form, 'createElement'), $element);
$element = $this->_form->addElement($element);
}
$element = $this->_form->addElement($element);
// Prepend standard CSS classes to the element classes.
$attributes = $element->getAttributes();