Items with images use own folder
Created 7 years ago by dwainsHi,
Currently i'm working on a pyro module which has items. Each item has a files field type. I want if you create a new item you upload the images to a temporary folder. After you save the item there must be a folder created with the id or title of the item and the item images need to be moved to there. So I don't get a folder with thousand of images. Also if you edit a item the new uploaded images must be uploaded in the existing item folder.
What is the best way to approach this?
Have you considered using tags rather than images for this? You could definitely programmatically create folders n stuff but the issue is it's not designed to handle thousands of folders. Thousands of images, yes. Folders, no.
Folders can take on custom fields too so you can use some kind of relation even if you wanted there too and maybe extend the files module a bit to make it easier to find things OR use the files table elsewhere / duplicate it in your addon for navigating in a specific way (you can extend it with MyFilesTableBuilder
for example in your addon).
Basically you're gonna end up with thousands of something. Folders or images. But I think meta fields could be used along with an area IN YOUR addon to better handle what you're after.
I now made a observer which calls a command with the help of piterden. But I got the following code:
public function handle(
FolderRepositoryInterface $folders,
DiskRepositoryInterface $disks
)
{
if (!$folder = $folders->findBySlug(md5($this->listing->getSlug()))) {
$disk = $disks->findBySlug('local');
$slug = $this->listing->getSlug();
//dd($slug);
$title = $this->listing->getTitle();
//dd($title . $slug);*/
$title = 'test'; $slug='test';
$hash = md5($slug);
$folder = $folders->create([
'nl' => [
'name' => 'test1'.$title,
'description' => "A folder for {$title}.",
],
'slug' => $hash,
'disk' => $disk,
'allowed_types' => [
'png',
'jpeg',
'jpg',
'gif',
'svg',
],
]);
}
return $folder;
}
It makes a folder in the db inside default_files_folders but it doesnt make the translations for it inside default_tiles_folders_translations is this a bug or?
I think you would need to build a custom FT in order to handle this :/.
I was thinking of needing something similar before but didn't have a way of doing it that I could find.