Items with images use own folder

dwains - 3 weeks ago

Hi,

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?

edster - 3 weeks ago

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.

ryanthompson - 3 weeks ago

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).

ryanthompson - 3 weeks ago

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.

dwains - 3 weeks ago

Okay so currenctly there isnt a good way to make this simple?

ryanthompson - 3 weeks ago

@dwains there is no baked in way to handle nested folders, no. But it wouldn't take much customization to handle it very well IMO.

dwains - 3 weeks ago

So you say make a field and assign it to itemsfolder and place all images inside that folder. Only custom files ft on the item edit that it only shows images from that item? or so

edster - 3 weeks ago

yea then have a handler or something that puts the item ID onto the file.

dwains - 3 weeks ago

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?