General developer forum

File manager in Block edit_form

 
Picture of Quentin Fombaron
File manager in Block edit_form
 

Hello everyone,


I've a problem with my filemanager in my edit_form.php


To save the data I use the function instance_config_save in my block_like.php :

public function instance_config_save($data, $nolongerused = false) {
$config = clone $data;
if (isset($config->likes_pix)) {
$config->likes_pix = file_save_draft_area_files(
$data->likes_pix,
$this->context->id,
'block_like',
'likes_pix',
0
);
}
parent::instance_config_save($config, $nolongerused);
}

The problem is that when I save a new config without giving any file, the old one are deleted, the solution is to load the old files in the filemanager but anything I'm trying don't works... I tried the set_data function in my edit_form.php but I don't really know how to use it :

public function set_data($defaults) {
$filemanageropts = array('subdirs' => 0, 'maxbytes' => 0, 'maxfiles' => 50);
$itemid = 0;
$draftitemid = file_get_submitted_draft_itemid('likes_pix');
file_prepare_draft_area(
$draftitemid,
$this->block->context->id,
'block_like',
'likes_pix',
$itemid,
$filemanageropts
);
$defaults->likes_pix = $draftitemid;
parent::set_data($defaults);
}

Some ideas to help me ? smile


Quentin

 
Average of ratings: -