#32 Fixed issue with images not loading from site templates
This commit is contained in:
parent
e5f5e4297a
commit
9224b057f7
1 changed files with 19 additions and 4 deletions
|
@ -101,10 +101,17 @@ class element extends \mod_customcert\element {
|
||||||
* @param \stdClass $data the form data
|
* @param \stdClass $data the form data
|
||||||
*/
|
*/
|
||||||
public function save_form_elements($data) {
|
public function save_form_elements($data) {
|
||||||
global $COURSE;
|
global $COURSE, $SITE;
|
||||||
|
|
||||||
|
// Set the context.
|
||||||
|
if ($COURSE->id == $SITE->id) {
|
||||||
|
$context = \context_system::instance();
|
||||||
|
} else {
|
||||||
|
$context = \context_course::instance($COURSE->id);
|
||||||
|
}
|
||||||
|
|
||||||
// Handle file uploads.
|
// Handle file uploads.
|
||||||
\mod_customcert\certificate::upload_imagefiles($data->customcertimage, \context_course::instance($COURSE->id)->id);
|
\mod_customcert\certificate::upload_imagefiles($data->customcertimage, $context->id);
|
||||||
|
|
||||||
parent::save_form_elements($data);
|
parent::save_form_elements($data);
|
||||||
}
|
}
|
||||||
|
@ -206,7 +213,7 @@ class element extends \mod_customcert\element {
|
||||||
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
* @param \mod_customcert\edit_element_form $mform the edit_form instance
|
||||||
*/
|
*/
|
||||||
public function definition_after_data($mform) {
|
public function definition_after_data($mform) {
|
||||||
global $COURSE;
|
global $COURSE, $SITE;
|
||||||
|
|
||||||
// Set the image, width and height for this element.
|
// Set the image, width and height for this element.
|
||||||
if (!empty($this->element->data)) {
|
if (!empty($this->element->data)) {
|
||||||
|
@ -216,9 +223,17 @@ class element extends \mod_customcert\element {
|
||||||
$this->element->height = $imageinfo->height;
|
$this->element->height = $imageinfo->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the context.
|
||||||
|
if ($COURSE->id == $SITE->id) {
|
||||||
|
$context = \context_system::instance();
|
||||||
|
} else {
|
||||||
|
$context = \context_course::instance($COURSE->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Editing existing instance - copy existing files into draft area.
|
// Editing existing instance - copy existing files into draft area.
|
||||||
$draftitemid = file_get_submitted_draft_itemid('customcertimage');
|
$draftitemid = file_get_submitted_draft_itemid('customcertimage');
|
||||||
file_prepare_draft_area($draftitemid, \context_course::instance($COURSE->id)->id, 'mod_customcert', 'image', 0, $this->filemanageroptions);
|
file_prepare_draft_area($draftitemid, $context->id, 'mod_customcert', 'image', 0, $this->filemanageroptions);
|
||||||
$element = $mform->getElement('customcertimage');
|
$element = $mform->getElement('customcertimage');
|
||||||
$element->setValue($draftitemid);
|
$element->setValue($draftitemid);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue