Please help - basic block development

Please help - basic block development

by Lorenzo Gaspari -
Number of replies: 0

Hello everybody,

I'm sure someone could help me, please help.

I followed this tutorial https://docs.moodle.org/dev/Blocks_Advanced

It's good, i've learned a lot of stuff but i'm stuck with the EDITOR element.

$mform->addElement('editor, ..., ... )

This is my view.php file (in bold the part where i'm stuck)

$elbloco->set_data($toform);
 
if($elbloco->is_cancelled()) {
$courseurl = new moodle_url('/course/view.php', array('id' => $id));
redirect($courseurl);
}
else if ($formobj = $elbloco->get_data()) {
if ($draftitemid = file_get_submitted_draft_itemid('eleditor')) {
$formobj->eleditor['text'] = file_save_draft_area_files($draftitemid, 35 , 'block_elbloco', 'elbloco', 0, array('subdirs' => true),$formobj->eleditor['text']);
$formobj->eleditorformat = $formobj->eleditor['format'];
$formobj->eleditor = $formobj->eleditor['text'] ;
}
if (!$DB->insert_record('elbloco', $formobj)) {
print_error('inserterror', 'block_elbloco');
}
$courseurl = new moodle_url('/course/view.php', array('id' => $courseid));
redirect($courseurl);

} else {
$site = get_site();
echo $OUTPUT->header();
if ($viewpage) {
$elblocopage = $DB->get_record('elbloco', array('id' => $id));
block_elbloco_print_page($elblocopage);
} else {
$elbloco->display();
}
echo $OUTPUT->footer();
}

And this is my lib.php file with the print_page (){} function

function block_elbloco_print_page($elbloco, $return = false) {

$messagetext = $elbloco->eleditor;
$messagetext = file_rewrite_pluginfile_urls($messagetext, 'pluginfile.php',
$PAGE->course->id, 'block_elbloco', 'elbloco', 0);
$formattedmessage =format_text($messagetext,FORMAT_HTML);

echo $formattedmessage;
}

I managed after time to save image url into database field and translate back with the rewrite function and i'm really happy about the progresses i made.

But now i cannot display the images. If i inspect the element i can see the link to the image correct, but the image is not being neither saved or displayed.

I'm almost sure that the the problem is that the files are not saved in directory or is something, that i do not know, related to the display of the image in the lib file.

If i inspect the area where the image should be I can see the correct link to the image src="http://localhost/pluginfile.php/2/block_elbloco/elbloco/0/harry.jpg" but the image (probably) is not there. As output i see only the image description.

I read million times: https://docs.moodle.org/dev/Using_the_File_API_in_Moodle_forms#editor but i need something simplier. I also checked what Davo said to look at mod/page/lib .

Following the suggestion i tried to create a data_preprocessing function but i got this error invoking lib/dml/mysqli_native_moodle_database.php error in line 1094 need a string parameter probably while trying to save my data to database.

I'll really appreciate an helping hand here, thanks a million.


Average of ratings: -