/** * Sets the data on the form when editing an element. * Can be overridden if more functionality is needed. * * @param mod_customcert_edit_element_form $mform the edit_form instance * @param array the form elements to set */ public function definition_after_data($mform) { // Loop through the properties of the element and set the values // of the corresponding form element, if it exists. foreach ($this->element as $property => $value) { if ($mform->elementExists($property)) { $element = $mform->getElement($property); $element->setValue($value); } } }
/** * Sets the data on the form when editing an element. * * @param mod_customcert_edit_element_form $mform the edit_form instance */ public function definition_after_data($mform) { global $COURSE; // Set the image, width and height for this element. $imageinfo = json_decode($this->element->data); $this->element->image = $imageinfo->pathnamehash; $this->element->width = $imageinfo->width; $this->element->height = $imageinfo->height; // Editing existing instance - copy existing files into draft area. $draftitemid = file_get_submitted_draft_itemid('customcertimage'); $filemanageroptions = array('maxbytes' => $COURSE->maxbytes, 'subdirs' => 1, 'accepted_types' => 'image'); file_prepare_draft_area($draftitemid, context_course::instance($COURSE->id)->id, 'mod_customcert', 'image', 0, $filemanageroptions); $element = $mform->getElement('customcertimage'); $element->setValue($draftitemid); parent::definition_after_data($mform); }