MDL-71517 mod_data: remove invalid form custom data access.

On PHP7.4, trying to access array offsets of NULL triggers a notice.
This commit is contained in:
Paul Holden 2021-05-04 15:25:57 +01:00
parent 0a986fdf13
commit 6b859f9481
2 changed files with 7 additions and 11 deletions

View File

@ -64,7 +64,6 @@ require_login($course, false, $cm);
$context = context_module::instance($cm->id);
require_capability('mod/data:manageentries', $context);
$form = new mod_data_import_form(new moodle_url('/mod/data/import.php'));
/// Print the page header
$PAGE->navbar->add(get_string('add', 'data'));
@ -78,14 +77,10 @@ echo $OUTPUT->heading_with_help(get_string('uploadrecords', 'mod_data'), 'upload
$currentgroup = groups_get_activity_group($cm);
$groupmode = groups_get_activity_groupmode($cm);
$form = new mod_data_import_form(new moodle_url('/mod/data/import.php'), ['dataid' => $data->id]);
if (!$formdata = $form->get_data()) {
/// Upload records section. Only for teachers and the admin.
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
require_once('import_form.php');
$form = new mod_data_import_form(new moodle_url('/mod/data/import.php'));
$formdata = new stdClass();
$formdata->d = $data->id;
$form->set_data($formdata);
$form->display();
echo $OUTPUT->box_end();
echo $OUTPUT->footer();

View File

@ -9,9 +9,9 @@ require_once($CFG->libdir.'/csvlib.class.php');
class mod_data_import_form extends moodleform {
function definition() {
global $CFG;
$mform =& $this->_form;
$cmid = $this->_customdata['id'];
$dataid = $this->_customdata['dataid'];
$mform->addElement('filepicker', 'recordsfile', get_string('csvfile', 'data'));
@ -21,15 +21,16 @@ class mod_data_import_form extends moodleform {
$mform->addElement('text', 'fieldenclosure', get_string('fieldenclosure', 'data'));
$mform->setType('fieldenclosure', PARAM_CLEANHTML);
$choices = core_text::get_encodings();
$mform->addElement('select', 'encoding', get_string('fileencoding', 'mod_data'), $choices);
$mform->setDefault('encoding', 'UTF-8');
$submit_string = get_string('submit');
// data id
// Database activity ID.
$mform->addElement('hidden', 'd');
$mform->setType('d', PARAM_INT);
$mform->setDefault('d', $dataid);
$this->add_action_buttons(false, $submit_string);
$this->add_action_buttons(false, get_string('submit'));
}
}